1.1.0 • Published 4 years ago
@essentials/memoize-one v1.1.0
A memoization algorithm that only caches the result of the latest set of arguments, where argument equality is determined via a provided equality function.
The default areEqual
function is a strict equality check on the first four arguments provided.
Quick Start
import memoOne from '@essentials/memoize-one'
const toUpper = memoOne(
(value) => value.toUpperCase(),
// are equal?
(args, prevArgs) => args[0] === prevArgs[0]
)
toUpper('foo')
// FOO (uncached)
toUpper('foo')
// FOO (cached)
toUpper('foobar')
// FOOBAR (uncached)
toUpper('foo')
// FOO (uncached)
API
memoOne(fn: Function, areEqual?: Function): any
Argument | Description |
---|---|
fn | The function you're memoizing the arguments and result of |
areEqual | An equality function. Return true if the arguments are equal, false if not. |
LICENSE
MIT