2.0.1 • Published 5 years ago
memoize-fn v2.0.1
memoize-fn
A memoization library that caches the result of the different arguments
Installation
npm install memoize-fn
# or use yarn
yarn add memoize-fnUsage
import memoizeFn from 'memoize-fn'
import { withCtx, robust } from 'memoize-fn'
let count = 1
const fn = memoizeFn(() => count++)
fn() // => 1
fn() // => 1
fn('new argument') // => 2
fn() // => 1
count // => 3API
memoize
Memoize function that caches the result of the different arguments.
Parameters
fn{Function}optionsObject {MemoizeOptions} (optional, default{})options.once(optional, defaultfalse)options.eq(optional, default(prevArgs,newArgs)=>shallowEqual(prevArgs,newArgs))options.cache(optional, defaultnew Map())options.skipEqualThis(optional, defaulttrue)
Returns any memoizeFn {Function}
withCtx
Memoize function that caches the result of the different arguments and with context
Parameters
fn{Function}opts{MemoizeOptions}
Returns CtxFunction
robust
Memoize function that caches the result of the different arguments and resets memoize function when catches error asynchronously.
Parameters
fn{Function}opts{MemoizeOptions}
Returns CtxFunction
MemoizeOptions
Type: {}
Parameters
once{boolean} - Only cache once like memoize-one (optional, defaultfalse)eq{(prevArgs, newArgs) => boolean} (optional, defaultshallowEqual)cache{Map} (optional, defaultnewMap())skipEqualThis{boolean} (optional, defaulttrue)
CtxFunction
Type: Function
Parameters
reset{Function} - Resets cacheunCache{Function} - Disables cache
Contributing
- Fork it!
- Create your new branch:
git checkout -b feature-neworgit checkout -b fix-which-bug - Start your magic work now
- Make sure npm test passes
- Commit your changes:
git commit -am 'feat: some description (close #123)'orgit commit -am 'fix: some description (fix #123)' - Push to the branch:
git push - Submit a pull request :)
Authors
This library is written and maintained by imcuttle, moyuyc95@gmail.com.
License
MIT - imcuttle 🐟