Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const kappa = require('kappa-core')
const View = require('kappa-view-level')
const ram = require('random-access-memory')
const level = require('level-mem')
const core = kappa(ram, { valueEncoding: 'json' })
const lvl = level()
let view = View(lvl, {
map: function (msg) {
return [[msg.value.key, msg.value.value]]
},
api: {
get (core, key) {
lvl.get(key, (err, res) => {
console.log(res)
})
}
}
})
core.use("incrementer", view)
core.writer("local", (err, feed) => {
for (let i = 0; i < 1000; i++) {
feed.append({key: `k-${i}`, value: i})
}
core.ready("incrementer", () => {
core.api.incrementer.get("k-999")
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment