-
Notifications
You must be signed in to change notification settings - Fork 4
/
ex.js
34 lines (28 loc) · 710 Bytes
/
ex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var kappa = require('kappa-core')
var View = require('.')
var ram = require('random-access-memory')
var memdb = require('memdb')
var core = kappa(ram, { valueEncoding: 'json' })
var lvl = memdb()
var view = View(lvl, {
map: function (msg) {
return [
[ msg.value.key, msg.value.value ]
]
},
api: {
get: function (key, cb) {
lvl.get(key, cb)
}
}
})
core.use('mapper', view)
core.feed(function (err, feed) {
feed.append({key: 'foo', value: 'bar'})
feed.append({key: 'bax', value: 'baz'})
core.ready('mapper', function () {
core.api.mapper.get('foo', console.log)
core.api.mapper.get('bax', console.log)
core.api.mapper.get('nix', console.log)
})
})