Skip to content

Commit afc8bd3

Browse files
committed
use an enum, and log arguments and inputs
1 parent a163264 commit afc8bd3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export { defaultMemoize, defaultEqualityCheck }
3838

3939
export type { DefaultMemoizeOptions }
4040

41-
type StabilityCheck = boolean | 'once'
41+
type StabilityCheck = 'always' | 'once' | 'never'
4242

4343
let globalStabilityCheck: StabilityCheck = 'once'
4444

@@ -159,7 +159,7 @@ export function createSelectorCreator<
159159

160160
if (
161161
process.env.NODE_ENV !== 'production' &&
162-
(finalStabilityCheck === true ||
162+
(finalStabilityCheck === 'always' ||
163163
(finalStabilityCheck === 'once' && firstRun))
164164
) {
165165
const paramsCopy = []
@@ -180,7 +180,12 @@ export function createSelectorCreator<
180180
'An input selector returned a different result when passed same arguments.' +
181181
'\nThis means your output selector will likely run more frequently than intended.' +
182182
'\nAvoid returning a new reference inside your input selector, e.g.' +
183-
'\n`createSelector([(arg1, arg2) => ({ arg1, arg2 })],(arg1, arg2) => {})`'
183+
'\n`createSelector([(arg1, arg2) => ({ arg1, arg2 })],(arg1, arg2) => {})`',
184+
{
185+
arguments,
186+
firstInputs: params,
187+
secondInputs: paramsCopy
188+
}
184189
)
185190
}
186191

test/inputStabilityCheck.spec.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,35 @@ describe('inputStabilityCheck', () => {
3232
expect(unstableInput).toHaveBeenCalledTimes(2)
3333

3434
expect(consoleSpy).toHaveBeenCalledWith(
35-
expect.stringContaining('An input selector returned a different result')
35+
expect.stringContaining('An input selector returned a different result'),
36+
expect.objectContaining({
37+
// IArguments isn't an array :(
38+
arguments: expect.anything(),
39+
firstInputs: expect.arrayContaining([
40+
expect.objectContaining({ a: 1, b: 2 })
41+
]),
42+
secondInputs: expect.arrayContaining([
43+
expect.objectContaining({ a: 1, b: 2 })
44+
])
45+
})
3646
)
3747
})
3848

3949
it('disables check if global setting is changed', () => {
40-
setInputStabilityCheckEnabled(false)
50+
setInputStabilityCheckEnabled('never')
4151

4252
expect(addNums(1, 2)).toBe(3)
4353

4454
expect(unstableInput).toHaveBeenCalledTimes(1)
4555

4656
expect(consoleSpy).not.toHaveBeenCalled()
4757

48-
setInputStabilityCheckEnabled(true)
58+
setInputStabilityCheckEnabled('once')
4959
})
5060

5161
it('disables check if specified in the selector options', () => {
5262
const addNums = createSelector([unstableInput], ({ a, b }) => a + b, {
53-
inputStabilityCheck: false
63+
inputStabilityCheck: 'never'
5464
})
5565

5666
expect(addNums(1, 2)).toBe(3)

0 commit comments

Comments
 (0)