ユーザーが指をタッチして数ピクセル動かすたびにイベントを発生させるイベント ストリームを作成したいと考えています。イベントには、ユーザーが移動した量による相対的な x と y の値が含まれている必要があります。次のコードはそれを正しく行います。
var extractTouchEvent = function (type) {
return extractEventE(document.body, type).mapE(function(e){
return {left:e.targetTouches[0].pageX, top:e.targetTouches[0].pageY};
});
};
var touchStartE = extractTouchEvent('touchstart');
var touchMoveE = extractTouchEvent('touchmove');
var draggedE = switchE(touchStartE.mapE(function(startValue){
return touchMoveE.mapE(function(moveValue){
return {left:moveValue.left-startValue.left, top:moveValue.top-startValue.top}
})
}));
しかし、ロギングを追加して変更すると、次のようになります。
var draggedE = switchE(touchStartE.mapE(function(startValue){
return touchMoveE.mapE(function(moveValue){
var a = {left:moveValue.left-startValue.left, top:moveValue.top- startValue.top};
console.log(a.left);
return a;
})
}));
結果のイベントの最新の EventStream のみを選択する switchE メソッドによってドロップされたにもかかわらず、過去のすべての touchmove EventStreams が各 touchmove イベントで引き続き評価されることがわかります。これらは、怠惰評価のこの巨大なリークを回避する方法ですか?