Mousetrap.js库允许将回调函数绑定到键,如下所示:
Mousetrap.bind('space', function, 'keydown');
在不使用Bus of Doom的情况下,附加流的最佳方法是什么?我应该使用emitter还是pool?
我正试着让箭头键连接在这个小提琴上:jsfiddle.net/vzafq25w
发布于 2015-05-15 09:20:14
您可以使用通用包装器stream。
var leftKeys = Kefir.stream(function(emitter){
Mousetrap.bind('left', function(e) {
emitter.emit(e);
console.log(e);
});
return function(){
// unbind
};
});http://jsfiddle.net/be9200kh/1/
发布于 2015-05-15 08:55:08
通常,您可以使用Kefir.fromEvents,但是在您的示例中,在Mousetrap.js不使用on|off方法绑定的情况下,您可以只使用Kefir.pool (Kefir.emitter被取消推荐)并在Mousetrap回调中触发Kefir。我修改了您的代码,以演示如何在Mousetrap回调:http://jsfiddle.net/be9200kh/中使用http://jsfiddle.net/be9200kh/
基本上,你知道
var pool = Kefir.pool();
pool.plug(Kefir.constant(1));
pool.map(...).filter(etc)玩得开心!
https://stackoverflow.com/questions/30249010
复制相似问题