javascript - 如何对 baconJS 中的 takeUntil 流使用react

标签 javascript frp bacon.js

我有 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/

相关文章:

javascript - Bacon.js 的评估模型是什么?

javascript - CodeIgniter 和 Javascript url 重写冲突

javascript - 淡入不起作用

javascript - 如何在没有 Fleegix.js 的情况下使用 timezone-js 加载时区文件?

javascript - bacon.js EventStream 表示每隔一段时间轮询 url

javascript - 将流映射到惰性 promise 流

javascript - 无法为 Unity 设置 UnityVS/Visual Studio 工具

ios - 使用 ReactiveCocoa 重试异步操作

haskell - Reactive-banana:来自 fromPoll 的最新值

haskell - 从箭头符号转换