kappa-core
Advanced tools
Comparing version 1.3.0 to 1.4.0
16
index.js
@@ -29,6 +29,20 @@ var hypercore = require('hypercore') | ||
for (var key in view.api) { | ||
this.api[name][key] = view.api[key].bind(this._indexes[name], this) | ||
this.api[name][key] = view.api[key].bind(this) | ||
} | ||
} | ||
Kappa.prototype.ready = function (viewNames, cb) { | ||
if (typeof viewNames === 'string') viewNames = [viewNames] | ||
if (viewNames.length === 0) return process.nextTick(cb) | ||
var pending = viewNames.length | ||
for (var i=0; i < viewNames.length; i++) { | ||
this._indexes[viewNames[i]].ready(done) | ||
} | ||
function done () { | ||
if (!--pending) cb() | ||
} | ||
} | ||
Kappa.prototype.feed = function (name, cb) { | ||
@@ -35,0 +49,0 @@ this._logs.writer(name, cb) |
@@ -5,3 +5,3 @@ { | ||
"author": "Stephen Whitmore <sww@eight.net>", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "git://github.com/noffle/kappa-core.git" |
@@ -19,4 +19,6 @@ # kappa-core | ||
var kappa = require('kappa-core') | ||
var memdb = require('memdb') | ||
var core = kappa('./log', { valueEncoding: 'json' }) | ||
var idx = memdb() | ||
@@ -38,3 +40,8 @@ var sum = 0 | ||
next() | ||
} | ||
}, | ||
// where to store and fetch the indexer's state (which log entries have been | ||
// processed so far) | ||
storeState: function (state, cb) { idx.put('state', state, cb) }, | ||
fetchState: function (cb) { idx.get('state', cb) } | ||
} | ||
@@ -102,4 +109,4 @@ | ||
The kappa-core instance `core` is always passed in as the first parameter. The | ||
underlying `multifeed-index` is bound to `this`. | ||
The kappa-core instance `core` is always is bound to `this` in all of the `api` | ||
functions you define. | ||
@@ -112,2 +119,14 @@ The `{fetch,store}State` functions are optional: they tell the view where to | ||
### core.ready(viewNames, cb) | ||
Wait until all views named by `viewNames` are caught up. e.g. | ||
``` | ||
// one | ||
core.ready('sum', function () { ... }) | ||
// or several | ||
core.ready(['kv', 'refs', 'spatial'], function () { ... }) | ||
``` | ||
### core.replicate([opts]) | ||
@@ -114,0 +133,0 @@ |
11526
71
190