- commit
- b7e6a8da035d65ad79ffd8bfd914c7ab4f20da6b
- parent
- e47b5dacbf512c94f78bbe9dda21d8a63e993c6f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-08 19:36
restore stagedChanges Our basic assumption is that concurrent editing in the same part of text is rare. However, out-of-order changes by a single peer looks a lot like concurrent editing in the same part of text. stagedChanges is used to ensure that a changeSet is not send before the previous one has been delivered.
Diffstat
M | static/pad.js | 16 | ++++++++++++++-- |
1 files changed, 14 insertions, 2 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -13,6 +13,7 @@ var el = document.querySelector('textarea'); 13 13 var old = el.value; 14 14 15 15 var localChanges = []; -1 16 var stagedChanges = []; 16 17 17 18 document.title += ' - ' + location.hash.slice(1); 18 19 @@ -23,8 +24,19 @@ var backup = utils.throttled(function() { 23 24 }, 10000); 24 25 25 26 var sendChanges = utils.throttled(function() {26 -1 via.send(room, [id, 'changes', localChanges]);27 -1 localChanges = [];-1 27 if (stagedChanges.length) { -1 28 setTimeout(sendChanges, 500); -1 29 } else { -1 30 stagedChanges = localChanges; -1 31 localChanges = []; -1 32 via.send(room, [id, 'changes', stagedChanges]).then(() => { -1 33 stagedChanges = []; -1 34 }).catch(() => { -1 35 localChanges = stagedChanges.concat(localChanges); -1 36 stagedChanges = []; -1 37 sendChanges(); -1 38 }); -1 39 } 28 40 }, 500); 29 41 30 42 var applyChanges = function(changes) {