Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
key/value join
var doc = new(require('crdt').Doc)
var contour = require('../')();
var reduce = contour.add({
from : [ 'output', 'test' ],
where : function (output, test) {
return output.test === test.id
},
init : {},
join : function (acc, output, test) {
var t = acc[test.id];
if (!t) t = acc[test.id] = { output : [] };
t.output.push(output.value);
return acc;
},
});
doc.on('add', contour.insert.bind(contour));
doc.add({
id : 'what',
type : 'output',
test : 'abc123',
value : 'beep '
});
doc.add({
type : 'output',
test : 'abc123',
value : 'boop\n'
});
doc.add({
type : 'test',
id : 'abc123',
commit : 'd8180b0778dd7a145b46f92b9a2d77db916debc5',
});
setTimeout(function () {
console.dir(contour.result);
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.