Comparing version 4.0.0 to 4.0.1
@@ -18,5 +18,19 @@ const set = require('unordered-set') | ||
const self = this | ||
const feed = this._db.feed | ||
const watchers = this._db._watchers | ||
if (onchange) this.on('change', onchange) | ||
set.add(this._db._watchers, this) | ||
set.add(watchers, this) | ||
this.update() | ||
if (watchers.length === 1 && feed.sparse) { | ||
feedUpdateLoop() | ||
} | ||
function feedUpdateLoop () { | ||
if (self._destroyed) return | ||
// TODO: Expose a way to cancel this update when the watcher is destroyed, since it is not ifAvailable. | ||
feed.update(feedUpdateLoop) | ||
} | ||
} | ||
@@ -23,0 +37,0 @@ |
{ | ||
"name": "hypertrie", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Distributed single writer key/value store", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -82,1 +82,24 @@ const tape = require('tape') | ||
}) | ||
tape('remote watch with sparse mode and live replication', function (t) { | ||
const db = create(null, { sparse: true }) | ||
db.ready(function () { | ||
const clone = create(db.key, { alwaysUpdate: true, sparse: true }) | ||
// The ready triggers an update, which we do not want to trigger a watch event, so we must call this first. | ||
clone.ready(function () { | ||
const stream = db.replicate(true, { live: true }) | ||
stream.pipe(clone.replicate(false, { live: true })).pipe(stream) | ||
var watcher = clone.watch(function () { | ||
t.pass('remote watch triggered') | ||
watcher.destroy() | ||
t.end() | ||
}) | ||
setTimeout(function () { | ||
db.put('hello', 'world') | ||
}, 50) | ||
}) | ||
}) | ||
}) |
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
100761
3132