1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var debounce = require("lodash/debounce");
|
4 | var factory_1 = require("./factory");
|
5 | var applicators_1 = require("./applicators");
|
6 | var decorator = factory_1.DecoratorFactory.createInstanceDecorator(new factory_1.DecoratorConfig(debounce, new applicators_1.PreValueApplicator(), { setter: true }));
|
7 | /**
|
8 | * Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.
|
9 | * The debounced function comes with a cancel method to cancel delayed func invocations and a flush method to immediately invoke them.
|
10 | * Provide options to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. The func is invoked with the last arguments provided to the debounced function.
|
11 | * Subsequent calls to the debounced function return the result of the last func invocation.
|
12 | *
|
13 | * Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the debounced function is invoked more than once during the wait timeout.
|
14 | *
|
15 | * If wait is 0 and leading is false, func invocation is deferred until to the next tick, similar to setTimeout with a timeout of 0.
|
16 | *
|
17 | * @param {number} [wait=0] The number in milliseconds to delay.
|
18 | * @param {DebounceOptions} [options] The options object.
|
19 | * @example
|
20 | *
|
21 | * class MyClass {
|
22 | * value = 100;
|
23 | *
|
24 | * @Debounce(10)
|
25 | * add(a) {
|
26 | * this.value += a;
|
27 | * }
|
28 | * }
|
29 | *
|
30 | * const myClass = new MyClass();
|
31 | *
|
32 | * myClass.add(10);
|
33 | * myClass.add(50);
|
34 | * myClass.add(20);
|
35 | *
|
36 | * myClass.value; // => 100;
|
37 | *
|
38 | * setTimeout(() => {
|
39 | * myClass.value; // => 120;
|
40 | * }, 11);
|
41 | */
|
42 | function Debounce(wait, options) {
|
43 | return decorator(wait, options);
|
44 | }
|
45 | exports.Debounce = Debounce;
|
46 | exports.debounce = Debounce;
|
47 | exports.default = decorator;
|
48 | //# sourceMappingURL=debounce.js.map |
\ | No newline at end of file |