scuttlebutt
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -37,3 +37,3 @@ var Scuttlebutt = require('./') | ||
emitter.histroy = function (filter) { | ||
emitter.history = function (filter) { | ||
var self = this | ||
@@ -40,0 +40,0 @@ var h = [] |
24
index.js
@@ -13,2 +13,3 @@ //really simple data replication. | ||
exports.createID = u.createID | ||
exports.updateIsRecent = u.filter | ||
exports.timestamp = u.timestamp | ||
@@ -60,3 +61,3 @@ | ||
sb.applyUpdate = dutyOfSubclass | ||
sb.histroy = dutyOfSubclass | ||
sb.history = dutyOfSubclass | ||
@@ -90,4 +91,3 @@ sb.localUpdate = function (key, value) { | ||
if(this.applyUpdate(update)) { | ||
emit.call(this, 'data', update) | ||
// emit.apply(this, ['update'].concat(update)) | ||
emit.call(this, '_update', update) | ||
return true | ||
@@ -108,10 +108,12 @@ } | ||
//if it's an object, it's a scuttlebut digest. | ||
if(Array.isArray(data) && validate(data)) | ||
return self._update(data) | ||
if('object' === typeof data && data) { | ||
if(Array.isArray(data)) { | ||
if(validate(data)) | ||
return self._update(data) | ||
} | ||
else if('object' === typeof data && data) { | ||
//when the digest is recieved from the other end, | ||
//send the histroy. | ||
//send the history. | ||
//merge with the current list of sources. | ||
sources = data | ||
i.each(self.histroy(sources), d.emitData.bind(d)) | ||
i.each(self.history(sources), d.emitData.bind(d)) | ||
d.emit('sync') | ||
@@ -121,3 +123,3 @@ } | ||
.on('close', function () { | ||
self.removeListener('update', onUpdate) | ||
self.removeListener('data', onUpdate) | ||
}) | ||
@@ -130,3 +132,3 @@ | ||
//if I put this after source[source]= ... it breaks tests | ||
d.emit('data', update) | ||
d.emitData(update) | ||
@@ -139,3 +141,3 @@ //really, this should happen before emitting. | ||
d.emitData(self.sources) | ||
self.on('data', onUpdate) | ||
self.on('_update', onUpdate) | ||
return d | ||
@@ -142,0 +144,0 @@ } |
@@ -41,3 +41,3 @@ var Scuttlebutt = require('./index') | ||
m.histroy = function (sources) { | ||
m.history = function (sources) { | ||
var self = this | ||
@@ -44,0 +44,0 @@ var h = [] |
@@ -5,3 +5,3 @@ { | ||
"description": "replicate data via scuttlebutt protocol", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"homepage": "https://github.com/dominictarr/scuttlebutt", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -22,3 +22,3 @@ | ||
, true | ||
, '_update returns true to indicate update applied') | ||
, 'write returns true to indicate update applied') | ||
@@ -28,3 +28,3 @@ console.log(g.store) | ||
assert.deepEqual(g.histroy(), [['key', value, source, ts]]) | ||
assert.deepEqual(g.history(), [['key', value, source, ts]]) | ||
@@ -35,6 +35,6 @@ var value2 = Math.random() | ||
, false | ||
, '_update returns false to indicate update did not apply') | ||
, 'write returns false to indicate update did not apply') | ||
//the second update was older, so must not be in the histroy | ||
assert.deepEqual(g.histroy(), [['key', value, source, ts]]) | ||
//the second update was older, so must not be in the history | ||
assert.deepEqual(g.history(), [['key', value, source, ts]]) | ||
@@ -62,3 +62,3 @@ assert.equal(g.get(key), value) | ||
assert.deepEqual( | ||
g.histroy(filter) | ||
g.history(filter) | ||
, []) | ||
@@ -69,14 +69,14 @@ | ||
assert.deepEqual( | ||
g.histroy(filter) | ||
, [['B', 'bbb', B, ts]]) | ||
g.history(filter) | ||
, [['B', 'bbb', B, ts]]) | ||
//if an item is not available, it | ||
//if an item is not available, it | ||
filter[C] = null | ||
assert.deepEqual( | ||
g.histroy(filter) | ||
g.history(filter) | ||
, [ ['B', 'bbb', B, ts] | ||
, ['C', 'ccc', C, ts]]) | ||
, ['C', 'ccc', C, ts]]) | ||
}) | ||
@@ -6,7 +6,8 @@ var gossip = require('../model') | ||
var g2 = gossip() | ||
var s1, s2 | ||
var s1, s2 | ||
(s1 = g1.createStream()) | ||
.pipe(s2 = g2.createStream()).pipe(s1) | ||
s1.on('data', console.log) | ||
s1.on('data', console.log.bind(console, "s1")) | ||
s2.on('data', console.log.bind(console, "s2")) | ||
@@ -13,0 +14,0 @@ //I like to have streams that work sync. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15297
14
367