@laserware/stasis
    Preparing search index...

    Function weakMapMemoize

    • Experimental

      Creates a tree of WeakMap-based cache nodes based on the identity of the arguments it's been called with (in this case, the extracted values from your input selectors). This allows weakMapMemoize to have an effectively infinite cache size. Cache results will be kept in memory as long as references to the arguments still exist, and then cleared out as the arguments are garbage-collected.

      Design Tradeoffs for weakMapMemoize:

      • Pros:
        • It has an effectively infinite cache size, but you have no control over how long values are kept in cache as it's based on garbage collection and WeakMaps.
      • Cons:
        • There's currently no way to alter the argument comparisons. They're based on strict reference equality.
        • It's roughly the same speed as lruMemoize, although likely a fraction slower.

      Use Cases for weakMapMemoize:

      • This memoizer is likely best used for cases where you need to call the same selector instance with many different arguments, such as a single selector instance that is used in a list item component and called with item IDs like:
        useSelector(state => selectSomeData(state, props.category))
        

      Type Parameters

      • Func extends AnyFunction

        The type of the function that is memoized.

      Parameters

      • func: Func

        The function to be memoized.

      • Optionaloptions: WeakMapMemoizeOptions<ReturnType<Func>>

      Returns Func & {
          clearCache: () => void;
          resetResultsCount: () => void;
          resultsCount: () => number;
      }

      A memoized function with a .clearCache() method attached.

      Using `createSelector` ```ts import { createSelector, weakMapMemoize } from 'reselect'

      interface RootState { items: { id: number; category: string; name: string }[] }

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

      
      
      Using `createSelectorCreator` ```ts import { createSelectorCreator, weakMapMemoize } from 'reselect'

      const createSelectorWeakMap = createSelectorCreator({ memoize: weakMapMemoize, argsMemoize: weakMapMemoize })

      const selectItemsByCategory = createSelectorWeakMap( [ (state: RootState) => state.items, (state: RootState, category: string) => category ], (items, category) => items.filter(item => item.category === category) )

      
      

      5.0.0