ottypes / json0

Version 0 of the JSON OT type
447 stars 64 forks source link

Fix transformComponent to handle subtypes that do not return arrays #11

Closed thomsbg closed 9 years ago

thomsbg commented 9 years ago

Needed to support rich-text for transform(). rich-text's transform function returns an object that does not pass a res.length > 0 test, and so is not appended correctly to dest.

This changes the logic to only perform the res.length > 0 test if res is an Array.

Some failing code that is now fixed:

var assert = require('assert');
var ot = require('ot-json0').type;
var a = [{ p: ['x'], t: 'rich-text', o: { ops: [{ insert: 'a' }] } }];
var b = [{ p: ['x'], t: 'rich-text', o: { ops: [{ insert: 'b' }] } }];
var t = [{ p: ['x'], t: 'rich-text', o: { ops: [{ retain: 1 }, { insert: 'a' }] } }];
ot.registerSubtype(require('rich-text').type);
assert.deepEqual(ot.transform(a, b, 'left'), t);
devongovett commented 9 years ago

Can you add a test?

thomsbg commented 9 years ago

@devongovett I added a test by depending on the rich-text library.

devongovett commented 9 years ago

We really should not depend on rich-text from here, even for the tests. You could just make a tiny subtype that tests just this particular behavior that you have changed.

thomsbg commented 9 years ago

Fixed to use a mock subtype

devongovett commented 9 years ago

Looks good to me! Thanks.

devongovett commented 9 years ago

@josephg can you do an npm release at some point for this? Thanks!

jvaill commented 6 years ago

Would love a release of this as well. Thanks 😸

josephg commented 6 years ago

Hah its been awhile. Let me get on that

josephg commented 6 years ago

Published @1.1.0