@ejfdelgado/ejflab-common 1.16.1 → 1.16.2
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/package.json +3 -2
- package/src/MyThrottle.js +5 -3
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ejfdelgado/ejflab-common",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/ejfdelgado/ejflab-common.git"
|
|
8
8
|
},
|
|
9
9
|
"description": "",
|
|
10
10
|
"scripts": {
|
|
11
|
+
"bip": "ffplay /sound/finish.mp3 -nodisp -nostats -hide_banner -autoexit",
|
|
11
12
|
"mylogin": "npm login",
|
|
12
|
-
"mypublish": "npm publish --access=public",
|
|
13
|
+
"mypublish": "npm publish --access=public && npm run bip",
|
|
13
14
|
"clean": "rm -rf node_modules && npm cache clean --force && rm package-lock.json && npm install"
|
|
14
15
|
},
|
|
15
16
|
"engines": {
|
package/src/MyThrottle.js
CHANGED
|
@@ -13,6 +13,8 @@ function debounce(fn, delay) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/*
|
|
16
|
+
IMPORTANT, the throttled function MUST be an async function, otherwise it will not work!
|
|
17
|
+
|
|
16
18
|
const GAP_ms = 500;
|
|
17
19
|
Si quieres tener en cuenta solo la primera invocación e ignorar las repetidas invocaciones con intervalos de menos de gap:
|
|
18
20
|
new MyThrottle(GAP_ms, true);
|
|
@@ -29,7 +31,7 @@ class MyThrottle {
|
|
|
29
31
|
this.isIgnoring = false;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
throttle(promisedFunction) {
|
|
34
|
+
throttle(promisedFunction, args = []) {
|
|
33
35
|
const afterGap = () => {
|
|
34
36
|
if (this.useFirst) {
|
|
35
37
|
if (calledTime == this.lastCalledTime) {
|
|
@@ -59,7 +61,7 @@ class MyThrottle {
|
|
|
59
61
|
// Use first
|
|
60
62
|
this.isCalling = true;
|
|
61
63
|
this.isIgnoring = true;
|
|
62
|
-
promisedFunction().finally(afterCall);
|
|
64
|
+
promisedFunction(...args).finally(afterCall);
|
|
63
65
|
setTimeout(afterGap, this.timeGap);
|
|
64
66
|
} else {
|
|
65
67
|
// Use last
|
|
@@ -67,7 +69,7 @@ class MyThrottle {
|
|
|
67
69
|
if (calledTime == this.lastCalledTime) {
|
|
68
70
|
// Call!
|
|
69
71
|
this.isCalling = true;
|
|
70
|
-
promisedFunction().finally(afterCall);
|
|
72
|
+
promisedFunction(...args).finally(afterCall);
|
|
71
73
|
} else {
|
|
72
74
|
console.log("Ignoring...");
|
|
73
75
|
}
|