我有 3 个用于 mouseDown、mouseUp 和 mouseMove 的事件流。到目前为止,当用户没有按下 alt
键时,它会在鼠标移动时执行某些操作,直到鼠标松开为止。
this.mouseDown
.filter((e) =>!e.altKey)
.flatMap(() => this.mouseMove.takeUntil(this.mouseUp))
.onValue((e) => this.setState({previewEndPoint: this.getNearestPoint(e)}));
我的问题是在这种情况下如何对鼠标松开事件使用react?
最佳答案
在doAction
中设置变量并在其他地方使用它确实是不好的信号并且没有必要。我重构了您的代码以使用组合流。
var moveStart = this.mousedown
.filter((e) =>!e.altKey && !e.metaKey)
var move = moveStart.flatMap((e) =>
this.mousemove
.takeUntil(this.mouseup)
.startWith(this.getNearestPoint(e))
);
var startPoint = moveStart.map((e) => this.getNearestPoint(e))
var endPoint = move.map((e) => this.getNearestPoint(e))
var preview = startPoint.combine(endPoint, (start, end) => {
preview: true,
startPoint: start,
previewEndPoint: end
})
preview.onValue((state) => this.setState(state));
move.onEnd(this.endLine.bind(this));
关于javascript - 如何对 baconJS 中的 takeUntil 流使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26399140/