UNPKG

1.28 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var memoize = require("lodash/memoize");
4var factory_1 = require("./factory");
5var applicators_1 = require("./applicators");
6/**
7 * Creates a function that memoizes the result of func. If resolver is provided,
8 * it determines the cache key for storing the result based on the arguments provided to the memoized function.
9 * By default, the first argument provided to the memoized function is used as the map cache key.
10 * The func is invoked with the this binding of the memoized function.
11 *
12 * You can use a Function or a string that references a method on the class as the resolver.
13 * You can also use a configuration object that lets provide a prexisting cache or specify
14 * the map type to use.
15 *
16 * @example
17 *
18 * class MyClass {
19 * @Memoize({ type: WeakMap })
20 * getName(item) {
21 * return item.name;
22 * }
23 *
24 * @Memoize('getName')
25 * getLastName(item) {
26 * return item.lastName;
27 * }
28 * }
29 */
30exports.Memoize = factory_1.DecoratorFactory.createInstanceDecorator(new factory_1.DecoratorConfig(memoize, new applicators_1.MemoizeApplicator(), { optionalParams: true }));
31exports.memoize = exports.Memoize;
32exports.default = exports.Memoize;
33//# sourceMappingURL=memoize.js.map
\No newline at end of file