Skip to content

Commit 9f133f9

Browse files
aryaemami59markerikson
authored andcommitted
Remove structuredClone from unit tests.
Substituted `deepClone` since Node 16 does not support `structuredClone`.
1 parent ad0d840 commit 9f133f9

File tree

4 files changed

+467
-683
lines changed

4 files changed

+467
-683
lines changed

src/createSelectorCreator.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defaultMemoize } from './defaultMemoize'
2+
23
import type {
34
Combiner,
45
CreateSelectorOptions,
@@ -12,12 +13,14 @@ import type {
1213
StabilityCheckFrequency,
1314
UnknownMemoizer
1415
} from './types'
16+
1517
import {
1618
assertIsFunction,
1719
collectInputSelectorResults,
1820
ensureIsArray,
1921
getDependencies,
20-
runStabilityCheck
22+
runStabilityCheck,
23+
shouldRunInputStabilityCheck
2124
} from './utils'
2225

2326
/**
@@ -30,7 +33,17 @@ export interface CreateSelectorFunction<
3033
MemoizeFunction extends UnknownMemoizer,
3134
ArgsMemoizeFunction extends UnknownMemoizer = typeof defaultMemoize
3235
> {
33-
/** Input selectors as separate inline arguments */
36+
/**
37+
* Creates a memoized selector function.
38+
*
39+
* @param createSelectorArgs - An arbitrary number of input selectors as separate inline arguments and a `combiner` function.
40+
* @returns An output selector.
41+
*
42+
* @template InputSelectors - The type of the input selectors as an array.
43+
* @template Result - The return type of the `combiner` as well as the output selector.
44+
* @template OverrideMemoizeFunction - The type of the optional `memoize` function that could be passed into the options object to override the original `memoize` function that was initially passed into `createSelectorCreator`.
45+
* @template OverrideArgsMemoizeFunction - The type of the optional `argsMemoize` function that could be passed into the options object to override the original `argsMemoize` function that was initially passed into `createSelectorCreator`.
46+
*/
3447
<InputSelectors extends SelectorArray, Result>(
3548
...createSelectorArgs: [
3649
...inputSelectors: InputSelectors,
@@ -43,7 +56,17 @@ export interface CreateSelectorFunction<
4356
ArgsMemoizeFunction
4457
>
4558

46-
/** Input selectors as separate inline arguments with memoizeOptions passed */
59+
/**
60+
* Creates a memoized selector function.
61+
*
62+
* @param createSelectorArgs - An arbitrary number of input selectors as separate inline arguments, a `combiner` function and an `options` object.
63+
* @returns An output selector.
64+
*
65+
* @template InputSelectors - The type of the input selectors as an array.
66+
* @template Result - The return type of the `combiner` as well as the output selector.
67+
* @template OverrideMemoizeFunction - The type of the optional `memoize` function that could be passed into the options object to override the original `memoize` function that was initially passed into `createSelectorCreator`.
68+
* @template OverrideArgsMemoizeFunction - The type of the optional `argsMemoize` function that could be passed into the options object to override the original `argsMemoize` function that was initially passed into `createSelectorCreator`.
69+
*/
4770
<
4871
InputSelectors extends SelectorArray,
4972
Result,
@@ -116,8 +139,8 @@ let globalStabilityCheck: StabilityCheckFrequency = 'once'
116139
* This function allows you to override this setting for all of your selectors.
117140
*
118141
* **Note**: This setting can still be overridden per selector inside `createSelector`'s `options` object.
119-
* See {@link https://github.com/reduxjs/reselect#per-selector-configuration | per-selector-configuration}
120-
* and {@linkcode CreateSelectorOptions.inputStabilityCheck | inputStabilityCheck} for more details.
142+
* See {@link https://github.com/reduxjs/reselect#per-selector-configuration per-selector-configuration}
143+
* and {@linkcode CreateSelectorOptions.inputStabilityCheck inputStabilityCheck} for more details.
121144
*
122145
* _The input stability check does not run in production builds._
123146
*
@@ -136,8 +159,8 @@ let globalStabilityCheck: StabilityCheckFrequency = 'once'
136159
* // Never run the input stability check.
137160
* setInputStabilityCheckEnabled('never')
138161
* ```
139-
* @see {@link https://github.com/reduxjs/reselect#development-only-checks | development-only-checks}
140-
* @see {@link https://github.com/reduxjs/reselect#global-configuration | global-configuration}
162+
* @see {@link https://github.com/reduxjs/reselect#development-only-checks development-only-checks}
163+
* @see {@link https://github.com/reduxjs/reselect#global-configuration global-configuration}
141164
*/
142165
export function setInputStabilityCheckEnabled(
143166
inputStabilityCheckFrequency: StabilityCheckFrequency
@@ -252,14 +275,14 @@ export function createSelectorCreator<
252275
: memoizeOrOptions
253276

254277
const createSelector = <
255-
Selectors extends SelectorArray,
278+
InputSelectors extends SelectorArray,
256279
Result,
257280
OverrideMemoizeFunction extends UnknownMemoizer = MemoizeFunction,
258281
OverrideArgsMemoizeFunction extends UnknownMemoizer = ArgsMemoizeFunction
259282
>(
260283
...funcs: [
261-
...inputSelectors: [...Selectors],
262-
combiner: Combiner<Selectors, Result>,
284+
...inputSelectors: [...InputSelectors],
285+
combiner: Combiner<InputSelectors, Result>,
263286
createSelectorOptions?: Partial<
264287
CreateSelectorOptions<
265288
MemoizeFunction,
@@ -287,7 +310,7 @@ export function createSelectorCreator<
287310

288311
// Normally, the result func or "combiner" is the last arg
289312
let resultFunc = funcs.pop() as
290-
| Combiner<Selectors, Result>
313+
| Combiner<InputSelectors, Result>
291314
| Partial<
292315
CreateSelectorOptions<
293316
MemoizeFunction,
@@ -301,7 +324,7 @@ export function createSelectorCreator<
301324
if (typeof resultFunc === 'object') {
302325
directlyPassedOptions = resultFunc
303326
// and pop the real result func off
304-
resultFunc = funcs.pop() as Combiner<Selectors, Result>
327+
resultFunc = funcs.pop() as Combiner<InputSelectors, Result>
305328
}
306329

307330
assertIsFunction(
@@ -310,7 +333,7 @@ export function createSelectorCreator<
310333
)
311334

312335
// Determine which set of options we're using. Prefer options passed directly,
313-
// but fall back to options given to createSelectorCreator.
336+
// but fall back to options given to `createSelectorCreator`.
314337
const combinedOptions = {
315338
...createSelectorCreatorOptions,
316339
...directlyPassedOptions
@@ -331,14 +354,17 @@ export function createSelectorCreator<
331354
// we wrap it in an array so we can apply it.
332355
const finalMemoizeOptions = ensureIsArray(memoizeOptions)
333356
const finalArgsMemoizeOptions = ensureIsArray(argsMemoizeOptions)
334-
const dependencies = getDependencies(funcs) as Selectors
357+
const dependencies = getDependencies(funcs) as InputSelectors
335358

336359
const memoizedResultFunc = memoize(function recomputationWrapper() {
337360
recomputations++
338361
// apply arguments instead of spreading for performance.
339362
// @ts-ignore
340-
return (resultFunc as Combiner<Selectors, Result>).apply(null, arguments)
341-
}, ...finalMemoizeOptions) as Combiner<Selectors, Result> &
363+
return (resultFunc as Combiner<InputSelectors, Result>).apply(
364+
null,
365+
arguments
366+
)
367+
}, ...finalMemoizeOptions) as Combiner<InputSelectors, Result> &
342368
ExtractMemoizerFields<OverrideMemoizeFunction>
343369

344370
let firstRun = true
@@ -360,12 +386,7 @@ export function createSelectorCreator<
360386
arguments
361387
)
362388

363-
const shouldRunInputStabilityCheck =
364-
process.env.NODE_ENV !== 'production' &&
365-
(inputStabilityCheck === 'always' ||
366-
(inputStabilityCheck === 'once' && firstRun))
367-
368-
if (shouldRunInputStabilityCheck) {
389+
if (shouldRunInputStabilityCheck(inputStabilityCheck, firstRun)) {
369390
// make a second copy of the params, to check if we got the same results
370391
const inputSelectorResultsCopy = collectInputSelectorResults(
371392
dependencies,
@@ -387,9 +408,9 @@ export function createSelectorCreator<
387408

388409
return lastResult
389410
}, ...finalArgsMemoizeOptions) as Selector<
390-
GetStateFromSelectors<Selectors>,
411+
GetStateFromSelectors<InputSelectors>,
391412
Result,
392-
GetParamsFromSelectors<Selectors>
413+
GetParamsFromSelectors<InputSelectors>
393414
> &
394415
ExtractMemoizerFields<OverrideArgsMemoizeFunction>
395416

@@ -403,7 +424,7 @@ export function createSelectorCreator<
403424
memoize,
404425
argsMemoize
405426
}) as OutputSelector<
406-
Selectors,
427+
InputSelectors,
407428
Result,
408429
OverrideMemoizeFunction,
409430
OverrideArgsMemoizeFunction

0 commit comments

Comments
 (0)