Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@essentials/memoize-one

jaredLunde107.8kMIT1.1.0TypeScript support: included

A memoization algorithm that only caches the result of the latest set of arguments, where argument equality is determined via a provided equality function.

memoize one, memoize, memo, fast memoize, fast memo, memo one

readme


@essentials/memoize-one

Bundlephobia Types NPM Version MIT License

npm i @essentials/memoize-one

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