我正在尝试了解 bacon.js 和 FRP,因此尝试制作一个简单的拖放示例,但是我在懒惰地评估一段代码时遇到了麻烦。当我将 a 添加.log()
到流中时,它看起来看起来和行为都很好,但是如果我把它拿出来,它就不会更新。这是我正在做的事情:
// UI streams
block_mousedown = block_el.asEventStream('mousedown').map(xyFromEvent);
global_mousemove = html.asEventStream('mousemove').map(xyFromEvent);
global_mouseup = html.asEventStream('mouseup');
// Composites
isDragging = block_mousedown.merge(global_mouseup.map(0));
mouseDragging = Bacon.combineAsArray(isDragging, global_mousemove)
.filter(function(v){ return notZero(v[0]) })
mouseDeltaFromClick = mouseDragging
.map(getDelta)
// Block offset when it was clicked on
block_pos_at_mousedown = block_mousedown
.map( function(a,b){ return block_el.offset();})
.map(function(e){ return [e.left, e.top]; })
// If I remove this log(), it doesn't evaluate
.log();
// merge mouse delta with block position when clicked
mouseDeltaAndBlockPos = mouseDeltaFromClick
.combine(block_pos_at_mousedown, '.concat')
.onValue( function(e){
block_el.css({
top : e[3]+e[1]+"px",
left : e[2]+e[0]+"px"
});
});
我在想我可能做错了,这甚至是正确的方法吗?我想在单击块时通过块的位置,该位置应该更新mousedown
但不与mousemove
.