From d7632a64e7520ad7cd8dda0a122aa6fa1afec78a Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Thu, 30 Nov 2023 18:20:56 -0600 Subject: [PATCH] Fix line endings --- src/defaultMemoize.ts | 14 +++++++------- src/types.ts | 2 +- src/weakMapMemoize.ts | 11 +++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/defaultMemoize.ts b/src/defaultMemoize.ts index bf5f0f25c..d590ebefd 100644 --- a/src/defaultMemoize.ts +++ b/src/defaultMemoize.ts @@ -126,7 +126,7 @@ export function createCacheKeyComparator(equalityCheck: EqualityFn) { /** * @public */ -export interface DefaultMemoizeOptions { +export interface DefaultMemoizeOptions { /** * Used to compare the individual arguments of the provided calculation function. * @@ -142,7 +142,7 @@ export interface DefaultMemoizeOptions { * use case, where an update to another field in the original data causes a recalculation * due to changed references, but the output is still effectively the same. */ - resultEqualityCheck?: EqualityFn + resultEqualityCheck?: EqualityFn /** * The cache size for the selector. If greater than 1, the selector will use an LRU cache internally. * @@ -167,7 +167,7 @@ export interface DefaultMemoizeOptions { */ export function defaultMemoize( func: Func, - equalityCheckOrOptions?: EqualityFn | DefaultMemoizeOptions + equalityCheckOrOptions?: EqualityFn | DefaultMemoizeOptions> ) { const providedOptions = typeof equalityCheckOrOptions === 'object' @@ -191,20 +191,20 @@ export function defaultMemoize( // we reference arguments instead of spreading them for performance reasons function memoized() { - let value = cache.get(arguments) + let value = cache.get(arguments) as ReturnType if (value === NOT_FOUND) { // @ts-ignore - value = func.apply(null, arguments) + value = func.apply(null, arguments) as ReturnType resultsCount++ if (resultEqualityCheck) { const entries = cache.getEntries() const matchingEntry = entries.find(entry => - resultEqualityCheck(entry.value, value) + resultEqualityCheck(entry.value as ReturnType, value) ) if (matchingEntry) { - value = matchingEntry.value + value = matchingEntry.value as ReturnType resultsCount-- } } diff --git a/src/types.ts b/src/types.ts index eb88c1f0e..ef613b644 100644 --- a/src/types.ts +++ b/src/types.ts @@ -295,7 +295,7 @@ export type Combiner = Distribute< * * @public */ -export type EqualityFn = (a: any, b: any) => boolean +export type EqualityFn = (a: T, b: T) => boolean /** * The frequency of input stability checks. diff --git a/src/weakMapMemoize.ts b/src/weakMapMemoize.ts index 7fa2c4cd3..564fb9d56 100644 --- a/src/weakMapMemoize.ts +++ b/src/weakMapMemoize.ts @@ -72,7 +72,7 @@ function createCacheNode(): CacheNode { /** * @public */ -export interface WeakMapMemoizeOptions { +export interface WeakMapMemoizeOptions { /** * If provided, used to compare a newly generated output value against previous values in the cache. * If a match is found, the old value is returned. This addresses the common @@ -82,7 +82,7 @@ export interface WeakMapMemoizeOptions { * use case, where an update to another field in the original data causes a recalculation * due to changed references, but the output is still effectively the same. */ - resultEqualityCheck?: EqualityFn + resultEqualityCheck?: EqualityFn } /** @@ -160,7 +160,7 @@ export interface WeakMapMemoizeOptions { */ export function weakMapMemoize( func: Func, - options: WeakMapMemoizeOptions = {} + options: WeakMapMemoizeOptions> = {} ) { let fnNode = createCacheNode() const { resultEqualityCheck } = options @@ -222,7 +222,10 @@ export function weakMapMemoize( if (resultEqualityCheck) { const lastResultValue = lastResult?.deref() ?? lastResult - if (lastResultValue != null && resultEqualityCheck(lastResultValue, result)) { + if ( + lastResultValue != null && + resultEqualityCheck(lastResultValue as ReturnType, result) + ) { result = lastResultValue resultsCount !== 0 && resultsCount-- }