UNPKG

859 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var once = require("lodash/once");
4var factory_1 = require("./factory");
5var applicators_1 = require("./applicators");
6/**
7 * Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation.
8 * @example
9 * class MyClass {
10 * value: number = 0;
11 *
12 * @Once()
13 * fn(): number {
14 * return ++this.value;
15 * }
16 * }
17 *
18 * const myClass = new MyClass();
19 *
20 * myClass.fn(); //=> 1
21 * myClass.fn(); //=> 1
22 * myClass.fn(); //=> 1
23 */
24exports.Once = factory_1.DecoratorFactory.createInstanceDecorator(new factory_1.DecoratorConfig(once, new applicators_1.PreValueApplicator(), { setter: true, optionalParams: true }));
25exports.once = exports.Once;
26exports.default = exports.Once;
27//# sourceMappingURL=once.js.map
\No newline at end of file