3.0.0 • Published 2 years ago
@prismamedia/ts-memoize v3.0.0
Typescript Memoize class method/getter decorator
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;
}
}