- commit
- 78db3410636c877607cd3493bcd7a7efaec89528
- parent
- a10f0508d6e7ea0039a5e83039e402548341de82
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-06 12:51
simplify throttle by removing leading call not relevevant for our case as the leading call usually only has a single change.
Diffstat
| M | static/pad.js | 2 | +- |
| M | static/utils.js | 24 | +++++++----------------- |
2 files changed, 8 insertions, 18 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -82,7 +82,7 @@ via.listen(room, function(msg) {
82 82 }
83 83 });
84 84
85 -1 window.addEventListener('beforeunload', backup.unblock);
-1 85 window.addEventListener('beforeunload', backup.wrapped);
86 86 window.addEventListener('offline', function() {
87 87 el.readOnly = true;
88 88 });
diff --git a/static/utils.js b/static/utils.js
@@ -11,27 +11,17 @@ export var randomString = function(length) {
11 11
12 12 export var throttled = function(fn, timeout) {
13 13 var blocked = false;
14 -1 var needsCall = false;
15 -1
16 -1 var unblock = function() {
17 -1 blocked = false;
18 -1 if (needsCall) {
19 -1 wrapper();
20 -1 }
21 -1 };
22 14
23 15 var wrapper = function() {
24 -1 if (blocked) {
25 -1 needsCall = true;
26 -1 return;
-1 16 if (!blocked) {
-1 17 blocked = true;
-1 18 setTimeout(function() {
-1 19 fn();
-1 20 blocked = false;
-1 21 }, timeout);
27 22 }
28 -1
29 -1 fn();
30 -1 blocked = true;
31 -1 needsCall = false;
32 -1 setTimeout(unblock, timeout);
33 23 };
34 24
35 -1 wrapper.unblock = unblock;
-1 25 wrapper.wrapped = fn;
36 26 return wrapper;
37 27 };