sharedb 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/doc.js +2 -2
- package/package.json +1 -1
- package/test/client/doc.js +30 -0
package/lib/client/doc.js
CHANGED
|
@@ -624,6 +624,8 @@ Doc.prototype._otApply = function(op, source) {
|
|
|
624
624
|
for (var i = 0; i < op.op.length; i++) {
|
|
625
625
|
var component = op.op[i];
|
|
626
626
|
var componentOp = {op: [component]};
|
|
627
|
+
// Apply the individual op component
|
|
628
|
+
this.emit('before op', componentOp.op, source, op.src);
|
|
627
629
|
// Transform componentOp against any ops that have been submitted
|
|
628
630
|
// sychronously inside of an op event handler since we began apply of
|
|
629
631
|
// our operation
|
|
@@ -631,8 +633,6 @@ Doc.prototype._otApply = function(op, source) {
|
|
|
631
633
|
var transformErr = transformX(this.applyStack[j], componentOp);
|
|
632
634
|
if (transformErr) return this._hardRollback(transformErr);
|
|
633
635
|
}
|
|
634
|
-
// Apply the individual op component
|
|
635
|
-
this.emit('before op', componentOp.op, source, op.src);
|
|
636
636
|
this._setData(this.type.apply(this.data, componentOp.op));
|
|
637
637
|
this.emit('op', componentOp.op, source, op.src);
|
|
638
638
|
}
|
package/package.json
CHANGED
package/test/client/doc.js
CHANGED
|
@@ -214,6 +214,36 @@ describe('Doc', function() {
|
|
|
214
214
|
});
|
|
215
215
|
});
|
|
216
216
|
|
|
217
|
+
it('remote ops are transformed by ops submitted in `before op` event handlers', function(done) {
|
|
218
|
+
var doc = this.doc;
|
|
219
|
+
var doc2 = this.doc2;
|
|
220
|
+
var doc3 = this.doc3;
|
|
221
|
+
function beforeOpHandler(op, source) {
|
|
222
|
+
if (source) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
doc.off('before op', beforeOpHandler);
|
|
226
|
+
doc.submitOp({p: ['list', 0], li: 2}, {source: true});
|
|
227
|
+
}
|
|
228
|
+
function opHandler(op, source) {
|
|
229
|
+
if (source) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
doc.off('op', opHandler);
|
|
233
|
+
doc.submitOp({p: ['list', 0], li: 3}, {source: true});
|
|
234
|
+
}
|
|
235
|
+
doc2.submitOp({p: ['list'], oi: []}, function() {
|
|
236
|
+
doc.fetch(function() {
|
|
237
|
+
doc.on('before op', beforeOpHandler);
|
|
238
|
+
doc.on('op', opHandler);
|
|
239
|
+
doc2.submitOp([{p: ['list', 0], li: 1}, {p: ['list', 1], li: 42}], function() {
|
|
240
|
+
doc.fetch();
|
|
241
|
+
verifyConsistency(doc, doc2, doc3, [], done);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
217
247
|
it('remote multi component ops are transformed by ops submitted in `op` event handlers', function(done) {
|
|
218
248
|
var doc = this.doc;
|
|
219
249
|
var doc2 = this.doc2;
|