Skip to content

Commit

Permalink
Add examples to lruMemoize JSDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Jan 3, 2024
1 parent c8263b5 commit bfbdba5
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/lruMemoize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,79 @@ export interface LruMemoizeOptions<Result = any> {
* @param equalityCheckOrOptions - Either an equality check function or an options object.
* @returns A memoized function with a `.clearCache()` method attached.
*
* @example
* <caption>Using `createSelector`</caption>
* ```ts
* import { shallowEqual } from 'react-redux'
* import { createSelector, lruMemoize } from 'reselect'
*
* export interface RootState {
* todos: {
* id: number
* completed: boolean
* title: string
* description: string
* }[]
* alerts: { id: number; read: boolean }[]
* }
*
* const selectTodoIds = createSelector(
* [(state: RootState) => state.todos],
* todos => todos.map(todo => todo.id),
* {
* memoize: lruMemoize,
* memoizeOptions: {
* equalityCheck: shallowEqual,
* resultEqualityCheck: shallowEqual,
* maxSize: 10
* },
* argsMemoize: lruMemoize,
* argsMemoizeOptions: {
* equalityCheck: shallowEqual,
* resultEqualityCheck: shallowEqual,
* maxSize: 10
* }
* }
* )
* ```
*
* @example
* <caption>Using `createSelectorCreator`</caption>
* ```ts
* import { shallowEqual } from 'react-redux'
* import { createSelectorCreator, lruMemoize } from 'reselect'
*
* export interface RootState {
* todos: {
* id: number
* completed: boolean
* title: string
* description: string
* }[]
* alerts: { id: number; read: boolean }[]
* }
*
* const createSelectorShallowEqual = createSelectorCreator({
* memoize: lruMemoize,
* memoizeOptions: {
* equalityCheck: shallowEqual,
* resultEqualityCheck: shallowEqual,
* maxSize: 10
* },
* argsMemoize: lruMemoize,
* argsMemoizeOptions: {
* equalityCheck: shallowEqual,
* resultEqualityCheck: shallowEqual,
* maxSize: 10
* }
* })
*
* const selectTodoIds = createSelectorShallowEqual(
* [(state: RootState) => state.todos],
* todos => todos.map(todo => todo.id)
* )
* ```
*
* @template Func - The type of the function that is memoized.
*
* @see {@link https://reselect.js.org/api/lruMemoize `lruMemoize`}
Expand Down

0 comments on commit bfbdba5

Please sign in to comment.