You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cryptpad/www/common/json-ot.js

31 lines
909 B
JavaScript

define([
'/common/realtime-input.js'
], function () {
var ChainPad = window.ChainPad;
var JsonOT = {};
var validate = JsonOT.validate = function (text, toTransform, 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.error(e);
console.log({
resultOp: resultOp,
text2: text2,
text3: text3
});
}
// returning **null** breaks out of the loop
// which transforms conflicting operations
// in theory this should prevent us from producing bad JSON
return null;
};
return JsonOT;
});