Download reselect/docs/examples/FAQ/selectorRecomputing.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 682 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/FAQ/selectorRecomputing.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/FAQ/selectorRecomputing.ts
-
curl -L -o selectorRecomputing.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/FAQ/selectorRecomputing.ts
682 Bytes
| import { createSelector, lruMemoize } from 'reselect' | |
| export interface RootState { | |
| todos: { id: number; completed: boolean }[] | |
| alerts: { id: number; read: boolean; type: string }[] | |
| } | |
| const selectAlertsByType = createSelector( | |
| [ | |
| (state: RootState) => state.alerts, | |
| (state: RootState, type: string) => type | |
| ], | |
| (alerts, type) => alerts.filter(todo => todo.type === type), | |
| { | |
| argsMemoize: lruMemoize, | |
| argsMemoizeOptions: { | |
| // This will check the arguments passed to the output selector. | |
| equalityCheck: (a, b) => { | |
| if (a !== b) { | |
| console.log('Changed argument:', a, 'to', b) | |
| } | |
| return a === b | |
| } | |
| } | |
| } | |
| ) | |