1.1.0 • Published 4 years ago

@essentials/memoize-one v1.1.0

Weekly downloads
1,699
License
MIT
Repository
github
Last release
4 years ago

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

ArgumentDescription
fnThe function you're memoizing the arguments and result of
areEqualAn equality function. Return true if the arguments are equal, false if not.

LICENSE

MIT