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

Allow passing in memoize functions directly to createSelector. #626

Merged
merged 58 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1b8791c
fixed one of the overloads
aryaemami59 Sep 29, 2023
32c7693
createSelector now accepts a memoizeMethod option that allows the use…
aryaemami59 Sep 29, 2023
d066563
Add type tests for `memoizeMethod`
aryaemami59 Sep 30, 2023
2d08a6e
Fix type issues for the new `createSelectorCreator` overload
aryaemami59 Oct 1, 2023
d46ce05
Remove generic `F` from `CreateSelectorFunction` and `createSelectorC…
aryaemami59 Oct 1, 2023
97a6880
Unify `createSelectorCreator` function signatures and removed overloa…
aryaemami59 Oct 1, 2023
6bdf561
Add separate options for memoize and argsMemoize in createSelectorCre…
aryaemami59 Oct 1, 2023
89e5bb1
Add minimal JSDoc for `setInputStabilityCheckEnabled` and `getDepende…
aryaemami59 Oct 1, 2023
6083103
Rename `memoizeMethod` and `argsMemoizeMethod` to `memoize` and `args…
aryaemami59 Oct 1, 2023
3311e78
CreateSelectorOptions now takes MemoizeFunction instead of MemoizeOpt…
aryaemami59 Oct 1, 2023
4c098a4
Rename UnknownFunction to AnyFunction
aryaemami59 Oct 1, 2023
481add2
Create more utility types
aryaemami59 Oct 1, 2023
6b040f8
Add argsMemoizeOptions to argsMemoize inside createSelectorCreator
aryaemami59 Oct 2, 2023
b77c8b1
Add JSDoc to CreateSelectorOptions
aryaemami59 Oct 2, 2023
b7eb24e
Remove `Keys` generic type parameter
aryaemami59 Oct 2, 2023
eac3213
Fix TS issues for the first overload of `createSelectorCreator`
aryaemami59 Oct 4, 2023
990b7b0
Simplify TS types for second overload of `createSelectorCreator`
aryaemami59 Oct 4, 2023
1058905
Fix runtime implementation of the new version of `createSelectorCreator`
aryaemami59 Oct 4, 2023
a17fdf8
Fix type inference issues with `CreateSelectorOptions`.
aryaemami59 Oct 4, 2023
db52127
Fix `CreateSelectorFunction` TS type inference issues.
aryaemami59 Oct 4, 2023
588bd16
Remove `CreateMemoizeOrOptions` utility type.
aryaemami59 Oct 4, 2023
3d80872
Fix runtime implementation of the new version of `createSelectorCreator`
aryaemami59 Oct 4, 2023
887bf54
Fix typo
aryaemami59 Oct 4, 2023
9b9de8f
Fix typo
aryaemami59 Oct 5, 2023
6113874
Convert `options` inside `createSelectorCreator` to if-else statement
aryaemami59 Oct 5, 2023
c30a741
Unify `memoizeOptions` type parameter in `createSelectorCreator` with…
aryaemami59 Oct 6, 2023
3189764
Clean up `CreateSelectorOptions`
aryaemami59 Oct 6, 2023
96022e3
Label parameters of `CreateSelectorFunction` for readability
aryaemami59 Oct 7, 2023
2ce44c2
Remove eslint's indent rule as it conflicts with prettier's formatting
aryaemami59 Oct 10, 2023
8fd2eae
Add `@internal` path to tsconfig for type tests
aryaemami59 Oct 10, 2023
e566c8a
Rename `argsMemoize` type test file
aryaemami59 Oct 10, 2023
57405b2
Move `memoize` and `argsMemoize` type tests into their file
aryaemami59 Oct 10, 2023
9cb9b9c
Add utils.ts file
aryaemami59 Oct 11, 2023
0601daf
Move `createSelectorCreator` and `createStructuredSelector` into thei…
aryaemami59 Oct 11, 2023
f4f63f5
Add `memoize` and `argsMemoize` to output selector fields in `createS…
aryaemami59 Oct 11, 2023
c2dd369
Rewrite, change and rename `DropFirst` to `DropFirstParameter`
aryaemami59 Oct 11, 2023
236f7bc
Add `Combiner` utility type
aryaemami59 Oct 11, 2023
e4dfbb8
Rewrite `OutputSelectorFields`
aryaemami59 Oct 11, 2023
b1cc274
Rewrite and simplify `OutputSelector`
aryaemami59 Oct 11, 2023
a43ad79
Rewrite `OutputParametricSelector`
aryaemami59 Oct 11, 2023
e3fbc56
Move `StabilityCheck` into types.ts
aryaemami59 Oct 11, 2023
5552281
Move `CreateSelectorOptions` into types.ts
aryaemami59 Oct 11, 2023
bebf23e
Simplify the description for properties inside `CreateSelectorOptions`
aryaemami59 Oct 11, 2023
383923b
Make minor type tweaks
aryaemami59 Oct 11, 2023
37c7cb9
Update JSDocs for `createSelectorCreator`
aryaemami59 Oct 11, 2023
002c2b8
Import and Use `AnyFunction` to replace its definition in order to mi…
aryaemami59 Oct 11, 2023
fa31fcd
Separate type imports from js imports
aryaemami59 Oct 11, 2023
ccfb005
Remove `esModuleInterop` from tsconfig
aryaemami59 Oct 11, 2023
8b89487
Fix export issues
aryaemami59 Oct 11, 2023
3b9778e
Simplify `Selector` type
aryaemami59 Oct 14, 2023
e0b9310
Swap generic slots for `Selectors` and `Result` inside `OutputSelector`
aryaemami59 Oct 14, 2023
87f8910
Create `runStabilityCheck` utility function
aryaemami59 Oct 14, 2023
2229d3c
Add additional JSDocs
aryaemami59 Oct 18, 2023
01a64f6
Add more JSDocs to some of the types
aryaemami59 Oct 24, 2023
0184db8
Fix importing issues in type test files.
aryaemami59 Oct 24, 2023
ad0d840
Fix type issues with lower TS versions
aryaemami59 Oct 24, 2023
9f133f9
Remove `structuredClone` from unit tests.
aryaemami59 Oct 25, 2023
9d7290f
Move NODE_ENV check up so debug checks are eliminated from prod
markerikson Oct 28, 2023
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
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"array-bracket-spacing": [0],
"comma-dangle": [2, "never"],
"eol-last": 2,
"indent": [2, 2, {
"SwitchCase": 1
}],
"no-multiple-empty-lines": 2,
"object-curly-spacing": [2, "always"],
"quotes": [2, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
Expand Down
7 changes: 4 additions & 3 deletions src/autotrackMemoize/autotrackMemoize.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createNode, updateNode } from './proxy'
import { Node } from './tracking'
import type { Node } from './tracking'

import { createCache } from './autotracking'
import {
createCacheKeyComparator,
defaultEqualityCheck
} from '@internal/defaultMemoize'
import type { AnyFunction } from '@internal/types'
import { createCache } from './autotracking'

export function autotrackMemoize<F extends (...args: any[]) => any>(func: F) {
export function autotrackMemoize<F extends AnyFunction>(func: F) {
// we reference arguments instead of spreading them for performance reasons

const node: Node<Record<string, unknown>> = createNode(
Expand Down
3 changes: 1 addition & 2 deletions src/autotrackMemoize/autotracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Additional references:
// - https://www.pzuraq.com/blog/how-autotracking-works
// - https://v5.chriskrycho.com/journal/autotracking-elegant-dx-via-cutting-edge-cs/
import type { EqualityFn } from '@internal/types'
import { assert } from './utils'

// The global revision clock. Every time state changes, the clock increments.
Expand All @@ -13,8 +14,6 @@ export let $REVISION = 0
// computing, then the tracker is null.
let CURRENT_TRACKER: Set<Cell<any> | TrackingCache> | null = null

type EqualityFn = (a: any, b: any) => boolean

// Storage represents a root value in the system - the actual state of our app.
export class Cell<T> {
revision = $REVISION
Expand Down
9 changes: 4 additions & 5 deletions src/autotrackMemoize/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Original source:
// - https://github.com/simonihmig/tracked-redux/blob/master/packages/tracked-redux/src/-private/proxy.ts

import type { Node, Tag } from './tracking'
import {
consumeCollection,
dirtyCollection,
Node,
Tag,
consumeTag,
dirtyTag,
createTag
createTag,
dirtyCollection,
dirtyTag
} from './tracking'

export const REDUX_PROXY_LABEL = Symbol()
Expand Down
6 changes: 3 additions & 3 deletions src/autotrackMemoize/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Cell } from './autotracking'
import {
createCell as createStorage,
getValue as consumeTag,
setValue,
Cell
createCell as createStorage,
setValue
} from './autotracking'

export type Tag = Cell<unknown>
Expand Down
Loading
Loading