Attempt an operational transformation and if the result is not valid JSON then fail

pull/1/head
Caleb James DeLisle 9 years ago
parent e16299b5c4
commit 37db31b09e

@ -1163,6 +1163,7 @@ module.exports.create = function (userName, authToken, channelId, initialState,
Common.assert(typeof(initialState) === 'string'); Common.assert(typeof(initialState) === 'string');
var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf); var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf);
return { return {
Operation: Operation,
onPatch: enterChainPad(realtime, function (handler) { onPatch: enterChainPad(realtime, function (handler) {
Common.assert(typeof(handler) === 'function'); Common.assert(typeof(handler) === 'function');
realtime.patchHandlers.push(handler); realtime.patchHandlers.push(handler);

@ -114,6 +114,11 @@ define([
transformBy: transformBy 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 // returning **null** breaks out of the loop
// which transforms conflicting operations // which transforms conflicting operations
// in theory this should prevent us from producing bad JSON // in theory this should prevent us from producing bad JSON

Loading…
Cancel
Save