Emit deltas in change over a stream
[key, value, sourceIdentifier, timestamp]
A delta-stream emits an array, where the first value is the key that has changed and the second value is the new value. This represents the delta in change on the object.
The third value is a source identifier. It's used to identify who created this delta
The fourth value is a time stamp which can be used for clever synchronization.
Create deltas that handle changes in state. Then create stream reprensentations of deltas
var Delta = require("delta-stream")
var delta1 = Delta()
, delta2 = Delta()
var stream1 = delta1.createStream()
, stream2 = delta2.createStream()
delta1.on("change:delta1", function (value) {
console.log("[CHANGE:DELTA1]", value)
})
delta2.on("change:delta2", function (value) {
console.log("[CHANGE:DELTA2]", value)
})
stream1.pipe(stream2).pipe(stream1)
delta1.set("delta2", "hello")
delta2.set("delta1", "world")
npm install delta-stream
- Raynos