<img src=https://secure.travis-ci.org/dominictarr/scuttlebutt.png?branch=master>
A base class that makes implementing datastructures for real-time replication easy.
This seems like a silly name, but I assure you, this is real science. read this: http://www.cs.cornell.edu/home/rvr/papers/flowgossip.pdf
or if you are lazy: http://en.wikipedia.org/wiki/Scuttlebutt (lazyness will get you nowhere, btw)
subclasses must implement at least histroy
and applyUpdate
sources
is a hash of source_ids: timestamps.
histroy must return an array of all known events from all sources
That occur after the given timestamps for each source.
The array MUST be in order by timestamp.
{ A: 0,
B: 2,
C: 3 }
Possibly apply a given update to the subclasses model. return true if the update was applied. (see scuttlebutt/model.js for an example of a subclass that does not apply every update)
var Model = require('scuttlebutt/model')
var a = new Model()
var b = new Model()
a.set(key, value)
b.on('update', console.log)
var s = a.createStream()
s.pipe(b.createStream()).pipe(s)
Any Scuttlebutt subclass is replicated with createStream.
var s = new Scuttlebutt()
var z = new Scuttlebutt()
var zs = z.createStream()
zs.pipe(s.createStream()).pipe(zs)
A Reliable event emmitter. Multiple instances of an emitter may be connected to each other and will remember events, so that they may be resent after a disconnection or crash.
With this approach it is also possible to persist events to disk, making them durable over crashes.
var Emitter = require('scuttlebutt/events')
var emitter = new Emitter()
emit an event. only one argument is permitted.
add an event listener.
A replicateable Model
object.
var Model = require('scuttlebutt/model')
var model = new Model()
Get a property
Set a property
Emmitted when a property changes.
If source !== this.id
then it was a remote update.