memoize-one
- Version 7.0.0
- Published
- 41.2 kB
- No dependencies
- MIT license
Install
npm i memoize-oneyarn add memoize-onepnpm add memoize-oneOverview
A memoization library which only remembers the latest invocation
Index
Functions
Type Aliases
Functions
function areInputsEqual
areInputsEqual: ( newInputs: readonly unknown[], lastInputs: readonly unknown[]) => boolean;The default equality check used by
memoizeOne.Returns
truewhen both lists have the same length, and each item is the same value according toObject.is.
function memoizeOne
memoizeOne: <TFunc extends (this: any, ...newArgs: any[]) => any>( resultFn: TFunc, isEqual?: EqualityFn<TFunc & {}>) => MemoizedFn<TFunc>;Memoize a function so that it only remembers the latest arguments and result.
The result function is called again when
thisor the arguments change. By default, arguments are compared withareInputsEqual(Object.ison each argument).Parameter resultFn
The function to memoize
Parameter isEqual
An optional custom equality function for the arguments
Type Aliases
type EqualityFn
type EqualityFn<TFunc extends (...args: any[]) => any = (...args: any[]) => any> = ( newArgs: Parameters<TFunc>, lastArgs: Parameters<TFunc>) => boolean;A function that decides if the new arguments are equal to the last arguments. Return
trueto use the cached result, orfalseto call the result function again.TFuncis the function being memoized. Without it,EqualityFnaccepts the arguments of any function, so you can write one equality function and reuse it.
type MemoizedFn
type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = { /** Clear the cache, so that the next call will call the result function again */ clear: () => void; (this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc>;};A memoized version of
TFunc. It has the samethistype, parameters and return type asTFunc, plus a.clear()function to clear the cache.Other properties of
TFuncare not copied. Because the call signature is rebuilt fromParametersandReturnType, only the last overload ofTFuncis kept, generic type parameters becomeunknown, and type predicates and assertion signatures no longer narrow.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (10)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/memoize-one.
- Markdown[](https://www.jsdocs.io/package/memoize-one)
- HTML<a href="https://www.jsdocs.io/package/memoize-one"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2370 ms. - Missing or incorrect documentation? Open an issue for this package.
