emberflow 1.3.89 → 1.3.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/functions.js +43 -21
- package/lib/utils/functions.js.map +1 -1
- package/package.json +1 -1
package/lib/utils/functions.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debounce = void 0;
|
|
4
4
|
function debounce(func, wait, maxWait, reducer) {
|
|
5
|
-
let accumulatedResult
|
|
6
|
-
let prevAccumulatedResult;
|
|
5
|
+
let accumulatedResult;
|
|
6
|
+
let prevAccumulatedResult;
|
|
7
7
|
let timeoutId;
|
|
8
8
|
let firstTimeCalled = null;
|
|
9
9
|
let lastTimeCalled = null;
|
|
@@ -16,9 +16,18 @@ function debounce(func, wait, maxWait, reducer) {
|
|
|
16
16
|
setImmediate(() => {
|
|
17
17
|
try {
|
|
18
18
|
const args = queue.shift();
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
if (!args) {
|
|
20
|
+
console.error("No args in queue. This should not happen");
|
|
21
|
+
return;
|
|
21
22
|
}
|
|
23
|
+
if (!reducer) {
|
|
24
|
+
console.error("Reducer is not defined. This should not happen");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (accumulatedResult === undefined) {
|
|
28
|
+
accumulatedResult = reducer.initialValueFactory();
|
|
29
|
+
}
|
|
30
|
+
reducer.reducerFn(accumulatedResult, ...args);
|
|
22
31
|
}
|
|
23
32
|
catch (error) {
|
|
24
33
|
console.error("Error processing queue:", error);
|
|
@@ -31,14 +40,6 @@ function debounce(func, wait, maxWait, reducer) {
|
|
|
31
40
|
}
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
|
-
const invokeFunction = (...args) => {
|
|
35
|
-
if (reducer && prevAccumulatedResult !== undefined) {
|
|
36
|
-
func(prevAccumulatedResult);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
func(...args);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
43
|
return function (...args) {
|
|
43
44
|
const now = new Date().getTime();
|
|
44
45
|
lastTimeCalled = now;
|
|
@@ -53,14 +54,22 @@ function debounce(func, wait, maxWait, reducer) {
|
|
|
53
54
|
queue.push(args);
|
|
54
55
|
processQueue();
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
const invokeFunction = (...args) => {
|
|
58
|
+
if (reducer) {
|
|
59
|
+
if (prevAccumulatedResult !== undefined) {
|
|
60
|
+
func(prevAccumulatedResult);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error("prevAccumulatedResult is undefined. This means that setImmediate are not yet executed. " +
|
|
64
|
+
"Let's debounce again");
|
|
65
|
+
initiateDebounce();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
func(...args);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function initiateDebounce() {
|
|
64
73
|
console.debug("debouncing");
|
|
65
74
|
timeoutId = setTimeout(() => {
|
|
66
75
|
if (lastTimeCalled) {
|
|
@@ -72,11 +81,24 @@ function debounce(func, wait, maxWait, reducer) {
|
|
|
72
81
|
}
|
|
73
82
|
console.debug("debounce timeout is reached");
|
|
74
83
|
prevAccumulatedResult = accumulatedResult;
|
|
75
|
-
accumulatedResult =
|
|
84
|
+
accumulatedResult = undefined; // Reset to a new initial value after executing
|
|
76
85
|
firstTimeCalled = null; // Reset timing
|
|
77
86
|
invokeFunction(...args);
|
|
78
87
|
}, wait);
|
|
79
88
|
}
|
|
89
|
+
function initiateMaxWaitReachedSequence() {
|
|
90
|
+
console.debug("debounce maxWait is reached");
|
|
91
|
+
prevAccumulatedResult = accumulatedResult;
|
|
92
|
+
accumulatedResult = undefined; // Reset to undefined
|
|
93
|
+
firstTimeCalled = null; // Reset timing
|
|
94
|
+
invokeFunction(...args);
|
|
95
|
+
}
|
|
96
|
+
if (maxWait && timeSinceFirstCalled >= maxWait) {
|
|
97
|
+
initiateMaxWaitReachedSequence();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
initiateDebounce();
|
|
101
|
+
}
|
|
80
102
|
};
|
|
81
103
|
}
|
|
82
104
|
exports.debounce = debounce;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/utils/functions.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CACtB,IAAyD,EACzD,IAAY,EACZ,OAAgB,EAChB,OAGC;IAED,IAAI,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/utils/functions.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CACtB,IAAyD,EACzD,IAAY,EACZ,OAAgB,EAChB,OAGC;IAED,IAAI,iBAAgC,CAAC;IACrC,IAAI,qBAAkC,CAAC;IACvC,IAAI,SAAqC,CAAC;IAC1C,IAAI,eAAe,GAAkB,IAAI,CAAC;IAC1C,IAAI,cAAc,GAAkB,IAAI,CAAC;IAEzC,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,SAAS,YAAY;QACnB,IAAI,UAAU;YAAE,OAAO;QACvB,UAAU,GAAG,IAAI,CAAC;QAElB,YAAY,CAAC,GAAG,EAAE;YAChB,IAAI;gBACF,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;gBAC3B,IAAI,CAAC,IAAI,EAAE;oBACT,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;oBAC3D,OAAO;iBACR;gBACD,IAAI,CAAC,OAAO,EAAE;oBACZ,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;oBACjE,OAAO;iBACR;gBAED,IAAI,iBAAiB,KAAK,SAAS,EAAE;oBACn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