Skip to content

Commit

Permalink
Merge pull request #709 from romgrk/fix-not-found
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Jun 1, 2024
2 parents 1223a1b + 3692d5c commit 649a63f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
DevModeChecksExecutionInfo
} from './types'

export const NOT_FOUND = 'NOT_FOUND'
export const NOT_FOUND = /* @__PURE__ */ Symbol('NOT_FOUND')
export type NOT_FOUND_TYPE = typeof NOT_FOUND

/**
Expand Down
32 changes: 32 additions & 0 deletions test/lruMemoize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,38 @@ describe(lruMemoize, () => {
expect(selector.resultFunc.clearCache).toBeUndefined()
})

test('cache miss identifier does not collide with state values', () => {
const state = ['NOT_FOUND', 'FOUND']

type State = typeof state

const createSelector = createSelectorCreator({
memoize: lruMemoize,
argsMemoize: lruMemoize
}).withTypes<State>()

const selector = createSelector(
[(state, id: number) => state[id]],
state => state,
{
argsMemoizeOptions: { maxSize: 10 },
memoizeOptions: { maxSize: 10 }
}
)

const firstResult = selector(state, 0)

expect(selector(state, 1)).toBe(selector(state, 1))

const secondResult = selector(state, 0)

expect(secondResult).toBe('NOT_FOUND')

expect(firstResult).toBe(secondResult)

expect(selector.recomputations()).toBe(2)
})

localTest(
'maxSize should default to 1 when set to a number that is less than 1',
({ state, store }) => {
Expand Down

0 comments on commit 649a63f

Please sign in to comment.