Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to unstable_autotrackMemoize and bump Vitest version #631

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@
"shelljs": "^0.8.5",
"tsup": "^6.7.0",
"typescript": "^4.9",
"vitest": "^0.29.8"
"vitest": "^0.34"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type {
SelectorResultArray
} from './types'

export { autotrackMemoize } from './autotrackMemoize/autotrackMemoize'
export { autotrackMemoize as unstable_autotrackMemoize } from './autotrackMemoize/autotrackMemoize'

export { weakMapMemoize } from './weakMapMemoize'

Expand Down
10 changes: 5 additions & 5 deletions test/autotrackMemoize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSelectorCreator, autotrackMemoize } from 'reselect'
import { createSelectorCreator, unstable_autotrackMemoize } from 'reselect'

// Construct 1E6 states for perf test outside of the perf test so as to not change the execute time of the test function
const numOfStates = 1000000
Expand All @@ -24,7 +24,7 @@ for (let i = 0; i < numOfStates; i++) {
}

describe('Basic selector behavior with autotrack', () => {
const createSelector = createSelectorCreator(autotrackMemoize)
const createSelector = createSelectorCreator(unstable_autotrackMemoize)

test('basic selector', () => {
// console.log('Selector test')
Expand Down Expand Up @@ -122,8 +122,8 @@ describe('Basic selector behavior with autotrack', () => {

expect(selector(state1)).toBe(3)
expect(selector.recomputations()).toBe(1)
// Expected a million calls to a selector with the same arguments to take less than 1 second
expect(totalTime).toBeLessThan(1000)
// Expected a million calls to a selector with the same arguments to take less than 2 seconds
expect(totalTime).toBeLessThan(2000)
})

test('basic selector cache hit performance for state changes but shallowly equal selector args', () => {
Expand All @@ -147,7 +147,7 @@ describe('Basic selector behavior with autotrack', () => {
expect(selector.recomputations()).toBe(1)

// Expected a million calls to a selector with the same arguments to take less than 1 second
expect(totalTime).toBeLessThan(1000)
expect(totalTime).toBeLessThan(2000)
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/perfComparisons.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PayloadAction } from '@reduxjs/toolkit'
import { configureStore, createSlice } from '@reduxjs/toolkit'
import {
autotrackMemoize,
unstable_autotrackMemoize,
createSelectorCreator,
defaultMemoize,
weakMapMemoize
Expand All @@ -19,7 +19,7 @@ describe('More perf comparisons', () => {
})

const csDefault = createSelectorCreator(defaultMemoize)
const csAutotrack = createSelectorCreator(autotrackMemoize)
const csAutotrack = createSelectorCreator(unstable_autotrackMemoize)

interface Todo {
id: number
Expand Down
10 changes: 5 additions & 5 deletions test/reselect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { configureStore, createSlice } from '@reduxjs/toolkit'
import lodashMemoize from 'lodash/memoize'
import microMemoize from 'micro-memoize'
import {
autotrackMemoize,
unstable_autotrackMemoize,
createSelector,
createSelectorCreator,
defaultMemoize,
Expand Down Expand Up @@ -507,7 +507,7 @@ describe<LocalTestContext>('argsMemoize and memoize', it => {
const selectorAutotrack = createSelector(
(state: TodoState) => state.todos,
todos => todos.map(({ id }) => id),
{ memoize: autotrackMemoize }
{ memoize: unstable_autotrackMemoize }
)
const outPutSelectorFields: (keyof OutputSelectorFields)[] = [
'memoize',
Expand Down Expand Up @@ -691,16 +691,16 @@ describe<LocalTestContext>('argsMemoize and memoize', it => {
// Call with new reference to force the selector to re-run
selectorOriginal(deepClone(state))
selectorOriginal(deepClone(state))
// Override `argsMemoize` with `autotrackMemoize`
// Override `argsMemoize` with `unstable_autotrackMemoize`
const selectorOverrideArgsMemoize = createSelector(
(state: TodoState) => state.todos,
todos => todos.map(({ id }) => id),
{
memoize: defaultMemoize,
memoizeOptions: { equalityCheck: (a, b) => a === b },
// WARNING!! This is just for testing purposes, do not use `autotrackMemoize` to memoize the arguments,
// WARNING!! This is just for testing purposes, do not use `unstable_autotrackMemoize` to memoize the arguments,
// it can return false positives, since it's not tracking a nested field.
argsMemoize: autotrackMemoize
argsMemoize: unstable_autotrackMemoize
}
)
selectorOverrideArgsMemoize(state)
Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"skipLibCheck": true,
"noImplicitReturns": false,
"noUnusedLocals": false,
"types": ["vitest/globals"],
"paths": {
"reselect": ["../src/index.ts"], // @remap-prod-remove-line
"@internal/*": ["src/*"]
Expand Down
44 changes: 27 additions & 17 deletions typescript_test/argsMemoize.typetest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoizeOne from 'memoize-one'
import microMemoize from 'micro-memoize'
import {
autotrackMemoize,
unstable_autotrackMemoize,
createSelector,
createSelectorCreator,
defaultMemoize,
Expand Down Expand Up @@ -46,26 +46,26 @@ function overrideOnlyMemoizeInCreateSelector() {
const selectorAutotrackSeparateInlineArgs = createSelector(
(state: State) => state.todos,
todos => todos.map(t => t.id),
{ memoize: autotrackMemoize }
{ memoize: unstable_autotrackMemoize }
)
const selectorAutotrackArgsAsArray = createSelector(
[(state: State) => state.todos],
todos => todos.map(t => t.id),
{ memoize: autotrackMemoize }
{ memoize: unstable_autotrackMemoize }
)
// @ts-expect-error When memoize is autotrackMemoize, type of memoizeOptions needs to be the same as options args in autotrackMemoize.
// @ts-expect-error When memoize is unstable_autotrackMemoize, type of memoizeOptions needs to be the same as options args in unstable_autotrackMemoize.
const selectorAutotrackArgsAsArrayWithMemoizeOptions = createSelector(
[(state: State) => state.todos],
// @ts-expect-error
todos => todos.map(t => t.id),
{ memoize: autotrackMemoize, memoizeOptions: { maxSize: 2 } }
{ memoize: unstable_autotrackMemoize, memoizeOptions: { maxSize: 2 } }
)
// @ts-expect-error When memoize is autotrackMemoize, type of memoizeOptions needs to be the same as options args in autotrackMemoize.
// @ts-expect-error When memoize is unstable_autotrackMemoize, type of memoizeOptions needs to be the same as options args in unstable_autotrackMemoize.
const selectorAutotrackSeparateInlineArgsWithMemoizeOptions = createSelector(
(state: State) => state.todos,
// @ts-expect-error
todos => todos.map(t => t.id),
{ memoize: autotrackMemoize, memoizeOptions: { maxSize: 2 } }
{ memoize: unstable_autotrackMemoize, memoizeOptions: { maxSize: 2 } }
)
const selectorWeakMapSeparateInlineArgs = createSelector(
(state: State) => state.todos,
Expand Down Expand Up @@ -93,7 +93,9 @@ function overrideOnlyMemoizeInCreateSelector() {
)
const createSelectorDefault = createSelectorCreator(defaultMemoize)
const createSelectorWeakMap = createSelectorCreator(weakMapMemoize)
const createSelectorAutotrack = createSelectorCreator(autotrackMemoize)
const createSelectorAutotrack = createSelectorCreator(
unstable_autotrackMemoize
)
const changeMemoizeMethodSelectorDefault = createSelectorDefault(
(state: State) => state.todos,
todos => todos.map(t => t.id),
Expand All @@ -110,7 +112,7 @@ function overrideOnlyMemoizeInCreateSelector() {
{ memoize: defaultMemoize }
)
const changeMemoizeMethodSelectorDefaultWithMemoizeOptions =
// @ts-expect-error When memoize is changed to weakMapMemoize or autotrackMemoize, memoizeOptions cannot be the same type as options args in defaultMemoize.
// @ts-expect-error When memoize is changed to weakMapMemoize or unstable_autotrackMemoize, memoizeOptions cannot be the same type as options args in defaultMemoize.
createSelectorDefault(
(state: State) => state.todos,
// @ts-expect-error
Expand Down Expand Up @@ -155,26 +157,32 @@ function overrideOnlyArgsMemoizeInCreateSelector() {
const selectorAutotrackSeparateInlineArgs = createSelector(
(state: State) => state.todos,
todos => todos.map(t => t.id),
{ argsMemoize: autotrackMemoize }
{ argsMemoize: unstable_autotrackMemoize }
)
const selectorAutotrackArgsAsArray = createSelector(
[(state: State) => state.todos],
todos => todos.map(t => t.id),
{ argsMemoize: autotrackMemoize }
{ argsMemoize: unstable_autotrackMemoize }
)
// @ts-expect-error When argsMemoize is autotrackMemoize, type of argsMemoizeOptions needs to be the same as options args in autotrackMemoize.
// @ts-expect-error When argsMemoize is unstable_autotrackMemoize, type of argsMemoizeOptions needs to be the same as options args in unstable_autotrackMemoize.
const selectorAutotrackArgsAsArrayWithMemoizeOptions = createSelector(
[(state: State) => state.todos],
// @ts-expect-error
todos => todos.map(t => t.id),
{ argsMemoize: autotrackMemoize, argsMemoizeOptions: { maxSize: 2 } }
{
argsMemoize: unstable_autotrackMemoize,
argsMemoizeOptions: { maxSize: 2 }
}
)
// @ts-expect-error When argsMemoize is autotrackMemoize, type of argsMemoizeOptions needs to be the same as options args in autotrackMemoize.
// @ts-expect-error When argsMemoize is unstable_autotrackMemoize, type of argsMemoizeOptions needs to be the same as options args in unstable_autotrackMemoize.
const selectorAutotrackSeparateInlineArgsWithMemoizeOptions = createSelector(
(state: State) => state.todos,
// @ts-expect-error
todos => todos.map(t => t.id),
{ argsMemoize: autotrackMemoize, argsMemoizeOptions: { maxSize: 2 } }
{
argsMemoize: unstable_autotrackMemoize,
argsMemoizeOptions: { maxSize: 2 }
}
)
const selectorWeakMapSeparateInlineArgs = createSelector(
(state: State) => state.todos,
Expand Down Expand Up @@ -202,7 +210,9 @@ function overrideOnlyArgsMemoizeInCreateSelector() {
)
const createSelectorDefault = createSelectorCreator(defaultMemoize)
const createSelectorWeakMap = createSelectorCreator(weakMapMemoize)
const createSelectorAutotrack = createSelectorCreator(autotrackMemoize)
const createSelectorAutotrack = createSelectorCreator(
unstable_autotrackMemoize
)
const changeMemoizeMethodSelectorDefault = createSelectorDefault(
(state: State) => state.todos,
todos => todos.map(t => t.id),
Expand All @@ -219,7 +229,7 @@ function overrideOnlyArgsMemoizeInCreateSelector() {
{ argsMemoize: defaultMemoize }
)
const changeMemoizeMethodSelectorDefaultWithMemoizeOptions =
// @ts-expect-error When argsMemoize is changed to weakMapMemoize or autotrackMemoize, argsMemoizeOptions cannot be the same type as options args in defaultMemoize.
// @ts-expect-error When argsMemoize is changed to weakMapMemoize or unstable_autotrackMemoize, argsMemoizeOptions cannot be the same type as options args in defaultMemoize.
createSelectorDefault(
(state: State) => state.todos,
// @ts-expect-error
Expand Down
Loading