pad

minimal etherpad alternative  https://pad.ce9e.org
git clone https://git.ce9e.org/pad.git

commit
993dfca7923325446a7924ae7cda58bc33aeec47
parent
52d98c11cbfcf6671ee96f48c60ee767d853eac2
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-06 03:46
refactor throttled

Diffstat

M static/pad.js 2 +-
M static/utils.js 20 +++++++++++---------

2 files changed, 12 insertions, 10 deletions


diff --git a/static/pad.js b/static/pad.js

@@ -90,4 +90,4 @@ setInterval(function() {
   90    90 	}
   91    91 }, 500);
   92    92 
   93    -1 window.addEventListener('beforeunload', () => backup(true));
   -1    93 window.addEventListener('beforeunload', backup.unblock);

diff --git a/static/utils.js b/static/utils.js

@@ -13,8 +13,15 @@ export var throttled = function(fn, timeout) {
   13    13 	var blocked = false;
   14    14 	var needsCall = false;
   15    15 
   16    -1 	var wrapper = function(force) {
   17    -1 		if (blocked && !force) {
   -1    16 	var unblock = function() {
   -1    17 		blocked = false;
   -1    18 		if (needsCall) {
   -1    19 			wrapper();
   -1    20 		}
   -1    21 	};
   -1    22 
   -1    23 	var wrapper = function() {
   -1    24 		if (blocked) {
   18    25 			needsCall = true;
   19    26 			return;
   20    27 		}
@@ -22,14 +29,9 @@ export var throttled = function(fn, timeout) {
   22    29 		fn();
   23    30 		blocked = true;
   24    31 		needsCall = false;
   25    -1 
   26    -1 		setTimeout(function() {
   27    -1 			blocked = false;
   28    -1 			if (needsCall) {
   29    -1 				wrapper();
   30    -1 			}
   31    -1 		}, timeout);
   -1    32 		setTimeout(unblock, timeout);
   32    33 	};
   33    34 
   -1    35 	wrapper.unblock = unblock;
   34    36 	return wrapper;
   35    37 };