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

Fix minor issues in docs #675

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5500ba3
Fix `createSelectorCreator` Parameters inside docs
aryaemami59 Jan 3, 2024
ca7a23c
Add `docusaurus-plugin-image-zoom` to dependencies
aryaemami59 Jan 3, 2024
717176e
Make images in docs zoomable
aryaemami59 Jan 3, 2024
d9cf2bd
Rename `babel.config.js` to `babel.config.cts`
aryaemami59 Jan 3, 2024
4b62e92
Slightly modify `.eslintrc` file to include `babel.config.cts` file
aryaemami59 Jan 3, 2024
2036241
Fix links inside `README` file
aryaemami59 Jan 3, 2024
f614e95
Fix `createSelectorCreator` Parameters inside `createSelectorCreator.…
aryaemami59 Jan 3, 2024
531a496
Specify default value in dev mode checks possible values in docs
aryaemami59 Jan 3, 2024
c8263b5
Slightly modify examples
aryaemami59 Jan 3, 2024
bfbdba5
Add examples to `lruMemoize` JSDocs
aryaemami59 Jan 3, 2024
684b00a
Modify examples inside `weakMapMemoize` JSDocs
aryaemami59 Jan 3, 2024
0805023
Update `lruMemoize` and `weakMapMemoize` documentation to highlight t…
aryaemami59 Jan 3, 2024
90bd935
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Jan 3, 2024
9c2f541
Remove unnecessary template tag from `CreateSelectorFunction` first o…
aryaemami59 Jan 3, 2024
aea5199
Fix JSDocs for `createStructuredSelector`
aryaemami59 Jan 3, 2024
a7ab21a
Add JSDocs to `weakMapMemoize` internals
aryaemami59 Jan 3, 2024
c80175e
Fix JSDocs for `getDevModeChecksExecutionInfo`
aryaemami59 Jan 3, 2024
16f1ff6
Fix link in JSDocs for `autotrackMemoize`
aryaemami59 Jan 3, 2024
93a4f7b
Merge branch 'fix-docs' of https://github.com/aryaemami59/reselect; b…
aryaemami59 Jan 5, 2024
7a07a54
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Jan 5, 2024
c7bcb3f
Fix lockfile issue
aryaemami59 Jan 5, 2024
bbbb21d
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Jan 7, 2024
c8e46cf
Modify JSDocs for `weakMapMemoize` internals
aryaemami59 Jan 7, 2024
509cd32
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Feb 10, 2024
262d444
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Feb 21, 2024
5165612
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Mar 8, 2024
a5aa796
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Mar 11, 2024
3ff9b5d
Undo some JSDoc changes in `types.ts`
aryaemami59 Mar 17, 2024
b224075
Revert "Modify JSDocs for `weakMapMemoize` internals"
aryaemami59 Mar 17, 2024
0cc366c
Revert "Fix link in JSDocs for `autotrackMemoize`"
aryaemami59 Mar 17, 2024
d78798a
Revert "Fix JSDocs for `getDevModeChecksExecutionInfo`"
aryaemami59 Mar 17, 2024
d560ca8
Revert "Add JSDocs to `weakMapMemoize` internals"
aryaemami59 Mar 17, 2024
b3dce8f
Revert "Fix JSDocs for `createStructuredSelector`"
aryaemami59 Mar 17, 2024
933b2de
Revert "Remove unnecessary template tag from `CreateSelectorFunction`…
aryaemami59 Mar 17, 2024
8c4ab20
Revert "Modify examples inside `weakMapMemoize` JSDocs"
aryaemami59 Mar 17, 2024
960cdf7
Revert "Add examples to `lruMemoize` JSDocs"
aryaemami59 Mar 17, 2024
0225078
Bump `docusaurus-plugin-image-zoom`
aryaemami59 Mar 17, 2024
8777313
Bump `docusaurus`
aryaemami59 Mar 17, 2024
f86f9fc
Bump `@docusaurus/types`
aryaemami59 Mar 17, 2024
d1799a6
Bump `@mdx-js/react`
aryaemami59 Mar 17, 2024
f760273
Add peer dependencies
aryaemami59 Mar 17, 2024
a465549
Cache Prettier usage
aryaemami59 Mar 17, 2024
2906c79
Revert "Bump `@mdx-js/react`"
aryaemami59 Mar 17, 2024
a3c3fc6
Add `@types/babel__core` to `devDependencies`
aryaemami59 Mar 17, 2024
c7d4745
Rename `monokaiTheme.js` to `monokaiTheme.ts`
aryaemami59 Mar 17, 2024
e400652
Change `monokaiTheme` to use ESM syntax and types
aryaemami59 Mar 17, 2024
e8aa19e
Import `monokaiTheme` instead of `require`
aryaemami59 Mar 17, 2024
4e159e1
Bump `prettier`
aryaemami59 Mar 17, 2024
07aaf1f
Format all files
aryaemami59 Mar 17, 2024
2659c89
Bump `ts-node`
aryaemami59 Mar 17, 2024
ce07c5d
Reapply "Fix JSDocs for `createStructuredSelector`"
aryaemami59 Mar 17, 2024
2e3cc71
Remove `require.resolve` usages from `docusaurus.config.ts`
aryaemami59 Mar 17, 2024
e3ebfa1
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 May 1, 2024
b9f1286
Merge branch 'master' of https://github.com/reduxjs/reselect into fix…
aryaemami59 Jun 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
},
{
"files": ["**/test/**/*.ts", "**/typescript_test/**/*.ts"],
"files": ["**/{test,typescript_test,type-tests}/**/*.{ts,tsx}"],
"rules": {
"consistent-return": "off",
"max-lines": "off",
Expand All @@ -77,7 +77,7 @@
"parser": "@typescript-eslint/parser",
"files": ["./docs/examples/**/*.{js,ts,jsx,tsx}"],
"parserOptions": {
"ecmaVersion": 2023,
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": { "jsx": true }
},
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ A library for creating memoized "selector" functions. Commonly used with Redux,

The **Redux docs usage page on [Deriving Data with Selectors](https://redux.js.org/usage/deriving-data-selectors)** covers the purpose and motivation for selectors, why memoized selectors are useful, typical Reselect usage patterns, and using selectors with [React-Redux].

<a id="installation" />

## Installation

### Redux Toolkit
Expand Down Expand Up @@ -38,16 +40,16 @@ yarn add reselect

The Reselect docs are available at **https://reselect.js.org**, and include usage guides and API references:

- [**Introduction**](#https://reselect.js.org/introduction/getting-started)
- [**How Does Reselect Work?**](#https://reselect.js.org/introduction/how-does-reselect-work)
- [**Introduction**](https://reselect.js.org/introduction/getting-started)
- [**How Does Reselect Work?**](https://reselect.js.org/introduction/how-does-reselect-work)
- **API Reference**:
- **[`createSelector`]**
- **[`createSelectorCreator`]**
- **[`createStructuredSelector`]**
- [**Development-Only Stability Checks**](#https://reselect.js.org/api/development-only-stability-checks)
- [**Development-Only Stability Checks**](https://reselect.js.org/api/development-only-stability-checks)
- **[`lruMemoize`]**
- **[`weakMapMemoize`]**
- [**FAQ**](#https://reselect.js.org/FAQ)
- [**FAQ**](https://reselect.js.org/FAQ)

## Basic Usage

Expand Down Expand Up @@ -162,7 +164,7 @@ These updates aim to enhance flexibility, performance, and developer experience.

- Removed `ParametricSelector` and `OutputParametricSelector` types. Their functionalities are now integrated into `Selector` and `OutputSelector` respectively, which inherently support additional parameters.

<div align="right">[ <a href="installation">↑ Back to top ↑</a> ]</div>
<div align="right">[ <a href="#installation">↑ Back to top ↑</a> ]</div>

---

Expand Down
9 changes: 3 additions & 6 deletions docs/examples/weakMapMemoize/cacheSizeSolution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSelector, weakMapMemoize } from 'reselect'
import { createSelector } from 'reselect'
import type { RootState } from './cacheSizeProblem'

const state: RootState = {
Expand All @@ -10,16 +10,13 @@ const state: RootState = {
]
}

// `createSelector` uses `weakMapMemoize` by default.
const selectItemsByCategory = createSelector(
[
(state: RootState) => state.items,
(state: RootState, category: string) => category
],
(items, category) => items.filter(item => item.category === category),
{
memoize: weakMapMemoize,
argsMemoize: weakMapMemoize
}
(items, category) => items.filter(item => item.category === category)
)

selectItemsByCategory(state, 'Electronics') // Selector runs
Expand Down
9 changes: 8 additions & 1 deletion docs/examples/weakMapMemoize/usingWithCreateSelector.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { shallowEqual } from 'react-redux'
import { createSelector, weakMapMemoize } from 'reselect'
import type { RootState } from './cacheSizeProblem'

Expand All @@ -18,7 +19,13 @@ const selectItemsByCategory = createSelector(
(items, category) => items.filter(item => item.category === category),
{
memoize: weakMapMemoize,
argsMemoize: weakMapMemoize
argsMemoize: weakMapMemoize,
argsMemoizeOptions: {
resultEqualityCheck: shallowEqual
},
memoizeOptions: {
resultEqualityCheck: shallowEqual
}
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { shallowEqual } from 'react-redux'
import { createSelectorCreator, weakMapMemoize } from 'reselect'
import type { RootState } from './cacheSizeProblem'

Expand All @@ -12,7 +13,13 @@ const state: RootState = {

const createSelectorWeakMap = createSelectorCreator({
memoize: weakMapMemoize,
argsMemoize: weakMapMemoize
argsMemoize: weakMapMemoize,
argsMemoizeOptions: {
resultEqualityCheck: shallowEqual
},
memoizeOptions: {
resultEqualityCheck: shallowEqual
}
})

const selectItemsByCategory = createSelectorWeakMap(
Expand Down
7 changes: 7 additions & 0 deletions website/babel.config.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TransformOptions } from '@babel/core'

const config: TransformOptions = {
presets: ['@docusaurus/core/lib/babel/preset']
}

export default config
3 changes: 0 additions & 3 deletions website/babel.config.js

This file was deleted.

18 changes: 9 additions & 9 deletions website/docs/api/createSelectorCreator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Accepts either a `memoize` function and `...memoizeOptions` rest parameter, or s

## Parameters (since 5.0.0)

| Name | Description |
| :----------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options` | An options object containing the `memoize` function responsible for memoizing the `resultFunc` inside <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). It also provides additional options for customizing memoization. While the `memoize` property is mandatory, the rest are optional. |
| `options.argsMemoize?` | The optional memoize function that is used to memoize the arguments passed into the <InternalLinks.OutputSelector /> generated by <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). <br /> **`Default`** = `lruMemoize` before 5.0.0 and `weakMapMemoize` after |
| `options.argsMemoizeOptions?` | Optional configuration options for the `argsMemoize` function. These options are passed to the `argsMemoize` function as the second argument. <br /> since 5.0.0 |
| `options.inputStabilityCheck?` | Overrides the global input stability check for the selector. Possible values are: <br /> `once` - Run only the first time the selector is called. <br /> `always` - Run every time the selector is called. <br /> `never` - Never run the input stability check. <br /> **`Default`** = `'once'` <br /> since 5.0.0 |
| `options.memoize` | The memoize function that is used to memoize the `resultFunc` inside <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). since 5.0.0 |
| `options.memoizeOptions?` | Optional configuration options for the `memoize` function. These options are passed to the `memoize` function as the second argument. <br /> since 5.0.0 |
| Name | Description |
| :---------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options` | An options object containing the `memoize` function responsible for memoizing the `resultFunc` inside <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). It also provides additional options for customizing memoization. While the `memoize` property is mandatory, the rest are optional. |
| `options.argsMemoize?` | The optional memoize function that is used to memoize the arguments passed into the <InternalLinks.OutputSelector /> generated by <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). <br /> **`Default`** = `lruMemoize` before 5.0.0 and `weakMapMemoize` after |
| `options.argsMemoizeOptions?` | Optional configuration options for the `argsMemoize` function. These options are passed to the `argsMemoize` function as the second argument. <br /> since 5.0.0 |
| `options.devModeChecks?` | Reselect performs [additional checks](https://reselect.js.org/api/development-only-stability-checks) in development mode to help identify and warn about potential issues in selector behavior. This option allows you to customize the behavior of these checks per selector. <br /> since 5.0.0 |
| `options.memoize` | The memoize function that is used to memoize the `resultFunc` inside <InternalLinks.CreateSelector /> (e.g., `lruMemoize` or `weakMapMemoize`). <br /> since 5.0.0 |
| `options.memoizeOptions?` | Optional configuration options for the `memoize` function. These options are passed to the `memoize` function as the second argument. <br /> since 5.0.0 |

## Parameters

Expand Down Expand Up @@ -69,7 +69,7 @@ customSelector(

The `memoize` argument is a memoization function to replace the default configured memoizer (normally `weakMapMemoize`).

The `...memoizeOptions` rest parameters are zero or more configuration options to be passed to `memoizeFunc`. The selectors `resultFunc` is passed as the first argument to `memoize` and the `memoizeOptions` are passed as the second argument onwards:
The `...memoizeOptions` rest parameters are zero or more configuration options to be passed to `memoizeFunc`. The selector's `resultFunc` is passed as the first argument to `memoize` and the `memoizeOptions` are passed as the second argument onwards:

```ts
const customSelectorCreator = createSelectorCreator(
Expand Down
20 changes: 10 additions & 10 deletions website/docs/api/development-only-stability-checks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Since this is a common mistake, we've added a development mode check to catch th
type DevModeCheckFrequency = 'always' | 'once' | 'never'
```

| Possible Values | Description |
| :-------------- | :---------------------------------------------- |
| `once` | Run only the first time the selector is called. |
| `always` | Run every time the selector is called. |
| `never` | Never run the input stability check. |
| Possible Values | Description |
| :-------------- | :-------------------------------------------------------- |
| `once` | Run only the first time the selector is called. (default) |
| `always` | Run every time the selector is called. |
| `never` | Never run the input stability check. |

:::info

Expand Down Expand Up @@ -158,11 +158,11 @@ const brokenSelector = createSelector(
type DevModeCheckFrequency = 'always' | 'once' | 'never'
```

| Possible Values | Description |
| :-------------- | :---------------------------------------------- |
| `once` | Run only the first time the selector is called. |
| `always` | Run every time the selector is called. |
| `never` | Never run the identity function check. |
| Possible Values | Description |
| :-------------- | :-------------------------------------------------------- |
| `once` | Run only the first time the selector is called. (default) |
| `always` | Run every time the selector is called. |
| `never` | Never run the identity function check. |

:::info

Expand Down
22 changes: 15 additions & 7 deletions website/docs/api/lruMemoize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ import { ExternalLinks } from '@site/src/components/ExternalLinks'

# `lruMemoize`

A memoization function that uses a provided equality check function to compare its inputs. This was originally known as `defaultMemoize`, and was the default inside of <InternalLinks.CreateSelector /> up through version 4.x.
:::info

- **Previous Versions:** Prior to version 5.0.0, Reselect used `lruMemoize` as the default memoizer in <InternalLinks.CreateSelector />. At that time, it was referred to as `defaultMemoize`.

- **Reselect 5.0.0 and Later:** Starting with version 5.0.0, Reselect has switched to using <InternalLinks.WeakMapMemoize /> as the default memoizer in <InternalLinks.CreateSelector />.

:::

A memoization function that uses a provided equality check function to compare its inputs. **This was originally known as `defaultMemoize`**, and was the default inside of <InternalLinks.CreateSelector /> up through version 4.x.

It has a default cache size of 1. This means it always recalculates when the value of an argument changes. However, this can be customized as needed with a specific max cache size (since 4.1.0).

Expand Down Expand Up @@ -57,7 +65,7 @@ const referenceEqualityCheck = (previousValue, currentValue) => {
| `func` | The function to be memoized. |
| `equalityCheckOrOptions` | Either an equality check function or an `options` object. |

Since 4.1.0, `lruMemoize` also accepts an options object as its first argument instead of an `equalityCheck` function. The `options` object may contain:
Since 4.1.0, `lruMemoize` also accepts an options object as its second argument instead of an `equalityCheck` function. The `options` object may contain:

```ts
type EqualityFn<T = any> = (a: T, b: T) => boolean
Expand All @@ -69,11 +77,11 @@ interface LruMemoizeOptions<Result = any> {
}
```

| Name | Description |
| :-------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `equalityCheck` | Used to compare the individual arguments of the provided calculation function. <br /> **`Default`** = `defaultEqualityCheck` |
| `resultEqualityCheck` | If provided, used to compare a newly generated output value against previous values in the cache. If a match is found, the old value is returned. This addresses the common <code>todos.map(todo => todo.id)</code> use case, where an update to another field in the original data causes a recalculation due to changed references, but the output is still effectively the same. |
| `maxSize` | The cache size for the selector. If greater than 1, the selector will use an LRU cache internally. <br /> **`Default`** = 1 |
| Name | Description |
| :-------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `equalityCheck` | Used to compare the individual arguments of the provided calculation function. <br /> **`Default`** = `referenceEqualityCheck` |
| `resultEqualityCheck` | If provided, used to compare a newly generated output value against previous values in the cache. If a match is found, the old value is returned. This addresses the common <code>todos.map(todo => todo.id)</code> use case, where an update to another field in the original data causes a recalculation due to changed references, but the output is still effectively the same. <br /> Since 4.1.0 |
| `maxSize` | The cache size for the selector. If greater than 1, the selector will use an LRU cache internally. <br /> **`Default`** = 1 |

:::warning

Expand Down