A Node.js library for sharing variables between 2 or more endpoints
This library is under development
const shared = new SharedVars();
const localVar = shared.assign({foo: 1, bar: 'hi'});
shared.bind(12345);
const shared2 = new SharedVars();
shared2.ping({ address: '127.0.0.1', port: 12345 });
const remoteVar = shared2.get(localVar.id);
remoteVar.once('update', timestamp => {
assert.deepEqual(remoteVar.value, localVar.value);
});
try {
remoteVar.set('hello');
} catch (err) {
assert.equal(err.message, 'This reference is readonly');
}
assert.equal(localVar.isWritable, true);
localVar.forward(shared2.address());
remoteVar.once('writable', () => {
remoteVar.set('hello');
});
localVar.once('update', timestamp => {
assert.equal(localVar.value, 'hello');
});
MIT License. Copyright © 2016 Moshe Simantov