Switch to patching with DiffDOM for testing :D

pull/1/head
Caleb James DeLisle 9 years ago
parent 2031191261
commit 86c4a69a97

@ -25,6 +25,7 @@
"ckeditor": "~4.5.6", "ckeditor": "~4.5.6",
"requirejs": "~2.1.15", "requirejs": "~2.1.15",
"modalBox": "~1.0.2", "modalBox": "~1.0.2",
"reconnectingWebsocket": "" "reconnectingWebsocket": "",
"diff-dom": "~2.0.0"
} }
} }

@ -230,8 +230,8 @@ define([
//verbose("Received own message"); //verbose("Received own message");
} else { } else {
//verbose("Received remote message"); //verbose("Received remote message");
// obviously this is only going to get called if // obviously this is only going to get called if
onRemote && onRemote(realtime.getAuthDoc()); onRemote && onRemote(realtime.getUserDoc());
} }
} }
} }
@ -290,7 +290,7 @@ define([
}); });
return { return {
onEvent: function () { onEvent: function () {
onEvent(); onEvent();
}, },
bumpSharejs: function () { bump(); } bumpSharejs: function () { bump(); }
}; };

@ -6,12 +6,15 @@ define([
'/common/convert.js', '/common/convert.js',
'/common/toolbar.js', '/common/toolbar.js',
'/common/cursor.js', '/common/cursor.js',
'/bower_components/diff-dom/diffDOM.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) { ], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
var $ = window.jQuery; var $ = window.jQuery;
var ifrw = $('#pad-iframe')[0].contentWindow; var ifrw = $('#pad-iframe')[0].contentWindow;
window.Ckeditor = ifrw.CKEDITOR; window.Ckeditor = ifrw.CKEDITOR;
var DiffDom = window.diffDOM;
var userName = Crypto.rand64(8), var userName = Crypto.rand64(8),
toolbar; toolbar;
@ -59,16 +62,11 @@ define([
var applyHjson = function (shjson) { var applyHjson = function (shjson) {
console.log("Applying HJSON"); console.log("Applying HJSON");
// before integrating external changes, check in your own var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson)));
vdom1 = Convert.dom.to.vdom(inner); userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf
// the authoritative document is hyperjson, parse it var patch = (new DiffDom()).diff(inner, userDocStateDom);
var authDoc = JSON.parse(shjson); console.log(userDocStateDom.outerHTML);
// use the authdoc to construct a second vdom (new DiffDom()).apply(inner, patch);
var vdom2 = Convert.hjson.to.vdom(authDoc);
// diff it against your version
var patches = Vdom.diff(vdom1, vdom2);
// apply the resulting patches
Vdom.patch(inner, patches);
}; };
var onRemote = function (shjson) { var onRemote = function (shjson) {
@ -104,7 +102,7 @@ define([
onInit: onInit, onInit: onInit,
transformFunction : function (text, toTransform, transformBy) { transformFunction : function (text, toTransform, transformBy) {
/* FIXME /* FIXME
operational transform on json shouldn't be in all editors operational transform on json shouldn't be in all editors
just those transmitting/expecting JSON just those transmitting/expecting JSON
*/ */

Loading…
Cancel
Save