Eventually-consistent, conflict-free replicated data types (CRDT) implemented using native Map
and Set
objects.
const { ObservedRemoveSet } = require('observed-remove');
const alice = new ObservedRemoveSet();
const bob = new ObservedRemoveSet();
alice.on('publish', (message) => {
setTimeout(() => bob.process(message), Math.round(Math.random() * 1000));
});
bob.on('publish', (message) => {
setTimeout(() => alice.process(message), Math.round(Math.random() * 1000));
});
alice.add('foo');
bob.add('bar');
// Later
alice.has('bar'); // true
bob.has('foo'); // true
const { ObservedRemoveMap } = require('observed-remove');
const alice = new ObservedRemoveMap();
const bob = new ObservedRemoveMap();
alice.on('publish', (message) => {
setTimeout(() => bob.process(message), Math.round(Math.random() * 1000));
});
bob.on('publish', (message) => {
setTimeout(() => alice.process(message), Math.round(Math.random() * 1000));
});
alice.set('a', 1);
bob.add('b', 2);
// Later
alice.get('b'); // 2
bob.get('a'); // 1
yarn add observed-remove