ts-memoize
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

ts-memoize

Use memoize pattern in your TypeScript code with only one API.

Installation

npm install ts-memoize
 
# or yarn 
yarn add ts-memoize

Usage

import memoize from 'ts-memoize';

For function:

const memoizedGetter = memoize((a, b) => {
  // the function should not depend on values outside of its scope
  return someHeavyRevaluation(a, b);
});

For class:

// on getter (& setter)
class A {
  @memoize
  public get a() {
    return someHeavyRevaluation();
  }
 
  public set value(val) {
    // re-evaluate when the setter is invoked
  }
}
 
// on method
class B {
  @memoize
  public getFunction(param) {
    // re-evaluate when arguments change
    return someHeavyRevaluation(param);
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i ts-memoize

Weekly Downloads

4

Version

0.2.0

License

MIT

Unpacked Size

19.2 kB

Total Files

15

Last publish

Collaborators

  • wendzhue