【问题标题】:What is RxJS (redux-observable) alternative to takeLatest from redux-saga?什么是来自 redux-saga 的 takeLatest 的 RxJS(redux-observable)替代品?
【发布时间】:2018-06-29 14:18:40
【问题描述】:

如果史诗接收到新动作,停止处理旧动作。 一点背景:我有一个史诗,它发出的延迟动作很少。 如果史诗收到新动作,我需要取消它们。

Redux-saga 效果正是我想要的: takeLatest

【问题讨论】:

    标签: rxjs redux-saga redux-observable


    【解决方案1】:

    这正是.switchMap 操作员所做的:

    将每个源值投影到一个 Observable 中,该 Observable 被合并到输出中 Observable,仅从最近投影的 Observable 发射值。

    在此示例中,您可以看到在新的 click 到达后,先前的 interval 不再处理:

    const clicks = Rx.Observable.fromEvent(document, 'click');
    const result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
    
    result.subscribe(x => console.log(x));
    <script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>
    <button>send new click</button>

    【讨论】:

      猜你喜欢
      • 2017-02-22
      • 2020-11-20
      • 2018-02-24
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 2018-06-02
      相关资源
      最近更新 更多