File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,7 @@ import type {
99 DevModeChecksExecutionInfo
1010} from './types'
1111
12- class NotFound { }
13-
14- export const NOT_FOUND = new NotFound ( )
12+ export const NOT_FOUND = Symbol ( 'NOT_FOUND' )
1513export type NOT_FOUND_TYPE = typeof NOT_FOUND
1614
1715/**
Original file line number Diff line number Diff line change @@ -421,6 +421,38 @@ describe(lruMemoize, () => {
421421 expect ( selector . resultFunc . clearCache ) . toBeUndefined ( )
422422 } )
423423
424+ test ( 'cache miss identifier does not collide with state values' , ( ) => {
425+ const state = [ 'NOT_FOUND' , 'FOUND' ]
426+
427+ type State = typeof state
428+
429+ const createSelector = createSelectorCreator ( {
430+ memoize : lruMemoize ,
431+ argsMemoize : lruMemoize
432+ } ) . withTypes < State > ( )
433+
434+ const selector = createSelector (
435+ [ ( state , id : number ) => state [ id ] ] ,
436+ state => state ,
437+ {
438+ argsMemoizeOptions : { maxSize : 10 } ,
439+ memoizeOptions : { maxSize : 10 }
440+ }
441+ )
442+
443+ const firstResult = selector ( state , 0 )
444+
445+ expect ( selector ( state , 1 ) ) . toBe ( selector ( state , 1 ) )
446+
447+ const secondResult = selector ( state , 0 )
448+
449+ expect ( secondResult ) . toBe ( 'NOT_FOUND' )
450+
451+ expect ( firstResult ) . toBe ( secondResult )
452+
453+ expect ( selector . recomputations ( ) ) . toBe ( 2 )
454+ } )
455+
424456 localTest (
425457 'maxSize should default to 1 when set to a number that is less than 1' ,
426458 ( { state, store } ) => {
You can’t perform that action at this time.
0 commit comments