无法将NeDB节点回调转换为Bacon EventStream

时间:2014-12-30 18:47:36

标签: javascript node.js coffeescript bacon.js nedb

Node callback NeDB下方正常工作,

Datastore = require 'nedb'
db = new Datastore

db.insert a: 'Hi!', (err, docs) -> 
    console.log docs

然后尝试将NeDB Node callback转换为Bacon EventStream

Bacon = require('baconjs').Bacon
Datastore = require 'nedb'
db = new Datastore

insert = Bacon.fromNodeCallback db.insert, a: 'Hi!'

insert.onValue (docs) ->
    console.log docs

为什么它在下面失败?

TypeError: Cannot call method 'push' of undefined

1 个答案:

答案 0 :(得分:1)

以这种方式传递db.insert时,会丢失其评估上下文(“this”不再是数据库)。尝试使用其他形式的fromNodeCallback

insert = Bacon.fromNodeCallback(db, 'insert', {a: 'Hi!'})