do not send deltas to worker synchronously since it is slow and crashes chrome

This commit is contained in:
nightwing 2013-04-09 16:44:17 +04:00
commit 477d381185
2 changed files with 19 additions and 7 deletions

View file

@ -12,7 +12,7 @@ var Mirror = exports.Mirror = function(sender) {
var _self = this;
sender.on("change", function(e) {
doc.applyDeltas([e.data]);
doc.applyDeltas(e.data);
deferredUpdate.schedule(_self.$timeout);
});
};

View file

@ -36,6 +36,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter;
var config = require("../config");
var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this);
this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
@ -152,17 +153,28 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
};
this.changeListener = function(e) {
e.range = {
start: e.data.range.start,
end: e.data.range.end
};
this.emit("change", e);
if (!this.deltaQueue) {
this.deltaQueue = [e.data];
setTimeout(this.$sendDeltaQueue, 1);
} else
this.deltaQueue.push(e.data);
};
this.$sendDeltaQueue = function() {
var q = this.deltaQueue;
if (!q) return;
this.deltaQueue = null;
if (q.length > 20 && q.length > this.$doc.getLength() >> 1) {
this.call("setValue", [this.$doc.getValue()]);
} else
this.emit("change", {data: q});
}
}).call(WorkerClient.prototype);
var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this);
this.callbackId = 1;
this.callbacks = {};
@ -207,6 +219,6 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
UIWorkerClient.prototype = WorkerClient.prototype;
exports.UIWorkerClient = UIWorkerClient;
exports.WorkerClient = WorkerClient;
exports.WorkerClient = UIWorkerClient;
});