3.0.0 • Published 2 years ago

@prismamedia/ts-memoize v3.0.0

Weekly downloads
131
License
MIT
Repository
github
Last release
2 years ago

Typescript Memoize class method/getter decorator

npm version github actions status code style: prettier

It's almost a copy/paste of https://github.com/darrylhodgins/typescript-memoize, without the legacy part

Usage

import { Memoize } from '@prismamedia/ts-memoize';
// or import Memoize from '@prismamedia/ts-memoize';

class Foo {
  @Memoize()
  public get myCachedGetter(): string {
    return 'OK';
  }

  @Memoize()
  public myCachedMethod(): string {
    return 'OK';
  }

  // If not provided, the "hashFunction" takes the first argument
  @Memoize()
  public myCachedMethod(input: string): string {
    return input;
  }

  // The "hashFunction" can return anything valid as a "Map" key
  @Memoize((a: number, b: number) => [a, b].join('|'))
  public myCachedMethod(a: number, b: number): number {
    return a + b;
  }
}