From 400f6efde15978f2755c8bc84bd0dc87a811e4d2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 12 Apr 2016 15:00:46 +0200 Subject: [PATCH 1/5] json-ot.js : jshint compliance --- www/common/json-ot.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/www/common/json-ot.js b/www/common/json-ot.js index 98e1af4ec..d8d75b7b6 100644 --- a/www/common/json-ot.js +++ b/www/common/json-ot.js @@ -5,15 +5,16 @@ define([ var JsonOT = {}; var validate = JsonOT.validate = function (text, toTransform, transformBy) { + var resultOp, text2, text3; try { // text = O (mutual common ancestor) // toTransform = A (the first incoming operation) // transformBy = B (the second incoming operation) // threeway merge (0, A, B) - var resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy); - var text2 = ChainPad.Operation.apply(transformBy, text); - var text3 = ChainPad.Operation.apply(resultOp, text2); + resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy); + text2 = ChainPad.Operation.apply(transformBy, text); + text3 = ChainPad.Operation.apply(resultOp, text2); try { JSON.parse(text3); return resultOp; @@ -35,8 +36,7 @@ define([ } } catch (x) { console.error(x); - console.error(e); - var info = window.REALTIME_MODULE.ot_applyError = { + window.REALTIME_MODULE.ot_applyError = { type: 'resultParseError', resultOp: resultOp, @@ -46,7 +46,7 @@ define([ text1: text, text2: text2, text3: text3, - error: e + error: x }; console.log('Debugging info available at `window.REALTIME_MODULE.ot_applyError`'); } From 851ccfbdb61929b3c888944585847eeb70f0ead4 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 12 Apr 2016 15:35:07 +0200 Subject: [PATCH 2/5] detect falsey operations in OT and ignore them --- www/common/json-ot.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/www/common/json-ot.js b/www/common/json-ot.js index d8d75b7b6..a785d524c 100644 --- a/www/common/json-ot.js +++ b/www/common/json-ot.js @@ -4,6 +4,9 @@ define([ var ChainPad = window.ChainPad; var JsonOT = {}; +/* FIXME + resultOp after transform0() might be null, in which case you should return null + because it is simply a transformation which yields a "do nothing" operation */ var validate = JsonOT.validate = function (text, toTransform, transformBy) { var resultOp, text2, text3; try { @@ -13,6 +16,11 @@ define([ // threeway merge (0, A, B) resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy); + + /* if after operational transform we find that no op is necessary + return null to ignore this patch */ + if (!resultOp) { return null; } + text2 = ChainPad.Operation.apply(transformBy, text); text3 = ChainPad.Operation.apply(resultOp, text2); try { From 2fdb4c12557466c192fef72fea7e3b4af2cfad1c Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 12 Apr 2016 15:07:31 +0200 Subject: [PATCH 3/5] ignore external files and anything relying on es6 merge differences from netflux Conflicts: .jshintignore --- .jshintignore | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.jshintignore b/.jshintignore index 29b53f0f4..3780e2719 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,6 +1,6 @@ node_modules/ www/bower_components/ -www/code/codemirror-5.7/ +www/code/codemirror* www/code/mode/ www/code/codemirror.js www/pad/rangy.js @@ -12,3 +12,14 @@ storage/kad.js www/common/otaml.js www/common/diffDOM.js www/common/netflux.js + +www/padrtc +www/common/netflux-client.js +www/common/es6-promise.min.js +www/_pad + +NetFluxWebsocketSrv.js +NetFluxWebsocketServer.js +WebRTCSrv.js + +www/assert/hyperscript.js From 368d72b337bd7d4981a249d55be4dc0271401d80 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 12 Apr 2016 14:51:06 +0200 Subject: [PATCH 4/5] add missing semicolons to TextPatcher.js --- www/common/TextPatcher.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/TextPatcher.js b/www/common/TextPatcher.js index 87cefa9dc..66858826d 100644 --- a/www/common/TextPatcher.js +++ b/www/common/TextPatcher.js @@ -40,7 +40,7 @@ var diff = function (oldval, newval) { toInsert: toInsert, toRemove: toRemove }; -} +}; /* patch accepts a realtime facade and an operation (which might be falsey) it applies the operation to the realtime as components (remove/insert) @@ -94,7 +94,7 @@ var create = function(config) { // *** remote -> local changes ctx.onPatch(function(pos, length) { - content = ctx.getUserDoc() + content = ctx.getUserDoc(); }); // propogate() From 2ffa69dc151915d7183f3023c4e9d915b9deb3bf Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 12 Apr 2016 15:55:03 +0200 Subject: [PATCH 5/5] remove checks for a non-existent race condition --- www/_socket/main.js | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/www/_socket/main.js b/www/_socket/main.js index bccdc99c6..67bfaff89 100644 --- a/www/_socket/main.js +++ b/www/_socket/main.js @@ -28,7 +28,6 @@ define([ toolbar; var module = window.REALTIME_MODULE = { - localChangeInProgress: 0, Hyperjson: Hyperjson, Hyperscript: Hyperscript }; @@ -187,23 +186,9 @@ define([ var DD = new DiffDom(diffOptions); - var localWorkInProgress = function (stage) { - if (module.localChangeInProgress) { - console.error("Applied a change while a local patch was in progress"); - console.error("local work was interrupted at stage: " + stage); - return true; - } - return false; - }; - // apply patches, and try not to lose the cursor in the process! var applyHjson = function (shjson) { - - localWorkInProgress(1); // check if this would interrupt local work - var userDocStateDom = hjsonToDom(JSON.parse(shjson)); - localWorkInProgress(2); // check again - /* in the DOM contentEditable is "false" while "contenteditable" is undefined. @@ -219,11 +204,8 @@ define([ this comes from hyperscript line 101. FIXME maybe */ userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf - localWorkInProgress(3); // check again var patch = (DD).diff(inner, userDocStateDom); - localWorkInProgress(4); // check again (DD).apply(inner, patch); - localWorkInProgress(5); // check again }; var initializing = true; @@ -231,8 +213,6 @@ define([ var onRemote = realtimeOptions.onRemote = function (info) { if (initializing) { return; } - localWorkInProgress(0); - var shjson = info.realtime.getUserDoc(); // remember where the cursor is @@ -290,20 +270,11 @@ define([ the code less extensible. */ var propogate = rti.onLocal = function () { - /* if the problem were a matter of external patches being - applied while a local patch were in progress, then we would - expect to be able to check and find - 'module.localChangeInProgress' with a non-zero value while - we were applying a remote change. - */ - module.localChangeInProgress += 1; var shjson = JSON.stringify(Hyperjson.fromDOM(inner, isNotMagicLine, brFilter)); if (!rti.patchText(shjson)) { - module.localChangeInProgress -= 1; return; } rti.onEvent(shjson); - module.localChangeInProgress -= 1; }; /* hitting enter makes a new line, but places the cursor inside