Kefir.js - 如何从回调函数中传输事件?

dpr*_*ren 8 javascript frp

Mousetrap.js库可以让您绑定的回调函数,像这样的键:

Mousetrap.bind('space', function, 'keydown');

在不使用末日巴士的情况下将流附加到此的最佳方法是什么?我应该使用emitterpool

我正试图在这个小提琴中连接箭头键:jsfiddle.net/vzafq25w

iof*_*sli 8

您可以使用通用包装器 stream

var leftKeys = Kefir.stream(function(emitter){
    Mousetrap.bind('left', function(e) {
        emitter.emit(e);
        console.log(e);
    });
    return function(){
        // unbind
    };
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/be9200kh/1/