From 37db31b09e9ec147385002f5b613168fc67f8e79 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Thu, 11 Feb 2016 12:34:06 +0100 Subject: [PATCH] Attempt an operational transformation and if the result is not valid JSON then fail --- www/common/chainpad.js | 1 + www/vdom/main.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/www/common/chainpad.js b/www/common/chainpad.js index 930ddb403..01aae63f9 100644 --- a/www/common/chainpad.js +++ b/www/common/chainpad.js @@ -1163,6 +1163,7 @@ module.exports.create = function (userName, authToken, channelId, initialState, Common.assert(typeof(initialState) === 'string'); var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf); return { + Operation: Operation, onPatch: enterChainPad(realtime, function (handler) { Common.assert(typeof(handler) === 'function'); realtime.patchHandlers.push(handler); diff --git a/www/vdom/main.js b/www/vdom/main.js index f8f13ce09..b734039b1 100644 --- a/www/vdom/main.js +++ b/www/vdom/main.js @@ -114,6 +114,11 @@ define([ transformBy: transformBy }); + var resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy); + var text2 = ChainPad.Operation.apply(transformBy, text); + var text3 = ChainPad.Operation.apply(resultOp, text2); + try { JSON.parse(text3); return resultOp; } catch (e) { console.log(e); } + // returning **null** breaks out of the loop // which transforms conflicting operations // in theory this should prevent us from producing bad JSON