Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow op to be a non-object #217

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ot.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exports.apply = function(snapshot, op) {
function applyOpEdit(snapshot, edit) {
if (!snapshot.type) return {code: 4015, message: 'Document does not exist'};

if (typeof edit !== 'object') return {code: 5004, message: 'Missing op'};
if (edit == null) return {code: 5004, message: 'Missing op'};
var type = types[snapshot.type];
if (!type) return {code: 4008, message: 'Unknown type'};

Expand Down
23 changes: 23 additions & 0 deletions test/client/number-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// A simple number type, where:
//
// - snapshot is an integer
// - operation is an integer
exports.type = {
name: 'number-type',
uri: 'http://sharejs.org/types/number-type',
create: create,
apply: apply,
transform: transform
};

function create(data) {
return data | 0;
}

function apply(snapshot, op) {
return snapshot + op;
}

function transform(op1, op2, side) {
return op1;
}
15 changes: 15 additions & 0 deletions test/client/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ var async = require('async');
var expect = require('expect.js');
var types = require('../../lib/types');
var deserializedType = require('./deserialized-type');
var numberType = require('./number-type');
types.register(deserializedType.type);
types.register(deserializedType.type2);
types.register(numberType.type);

module.exports = function() {
describe('client submit', function() {
Expand Down Expand Up @@ -1044,6 +1046,19 @@ describe('client submit', function() {
});
});

it('allows snapshot and op to be a non-object', function(done) {
var doc = this.backend.connect().get('dogs', 'fido');
doc.create(5, numberType.type.uri, function (err) {
if (err) return done(err);
expect(doc.data).to.equal(5);
doc.submitOp(2, function(err) {
if (err) return done(err);
expect(doc.data).to.equal(7);
done();
});
});
});

describe('type.deserialize', function() {
it('can create a new doc', function(done) {
var doc = this.backend.connect().get('dogs', 'fido');
Expand Down