Skip to content

Commit d1ca2ae

Browse files
committed
Do not compose create with op
The problem is that the `create` operation contains initial data rather than a snapshot and `apply` requires the first param to be a snapshot. So, the original implementation worked only for the types which have the same type of initial data and snapshots.
1 parent 68bde00 commit d1ca2ae

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

lib/client/doc.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,6 @@ Doc.prototype._tryCompose = function(op) {
714714
var last = this.pendingOps[this.pendingOps.length - 1];
715715
if (!last) return;
716716

717-
// Compose an op into a create by applying it. This effectively makes the op
718-
// invisible, as if the document were created including the op originally
719-
if (last.create && op.op) {
720-
last.create.data = this.type.apply(last.create.data, op.op);
721-
return last;
722-
}
723-
724717
// Compose two ops into a single op if supported by the type. Types that
725718
// support compose must be able to compose any two ops together
726719
if (last.op && op.op && this.type.compose) {

test/client/submit.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,24 @@ describe('client submit', function() {
119119

120120
it('ops submitted sync get composed', function(done) {
121121
var doc = this.backend.connect().get('dogs', 'fido');
122-
doc.create({age: 3});
123-
doc.submitOp({p: ['age'], na: 2});
122+
doc.create({age: 5});
124123
doc.submitOp({p: ['age'], na: 2}, function(err) {
125124
if (err) return done(err);
126125
expect(doc.data).eql({age: 7});
127-
// Version is 1 instead of 3, because the create and ops got composed
128-
expect(doc.version).eql(1);
126+
// create DOES NOT get composed
127+
expect(doc.version).eql(2);
129128
doc.submitOp({p: ['age'], na: 2});
130129
doc.submitOp({p: ['age'], na: 2}, function(err) {
131130
if (err) return done(err);
132131
expect(doc.data).eql({age: 11});
133-
// Ops get composed
134-
expect(doc.version).eql(2);
132+
// Version is 3 instead of 4, because the ops got composed
133+
expect(doc.version).eql(3);
135134
doc.submitOp({p: ['age'], na: 2});
136135
doc.del(function(err) {
137136
if (err) return done(err);
138137
expect(doc.data).eql(undefined);
139138
// del DOES NOT get composed
140-
expect(doc.version).eql(4);
139+
expect(doc.version).eql(5);
141140
done();
142141
});
143142
});

0 commit comments

Comments
 (0)