redux-observable 中的独立链取消? [英] Independent chain cancellation in redux-observable?

查看:21
本文介绍了redux-observable 中的独立链取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 RxJS 的新手.在我的应用程序中,我需要独立取消延迟操作.这是一个工作示例(延迟为 3 秒).但是当我选择删除多个项目并取消其中一个时,又一次全部取消.

I'm new to RxJS. In my app I need independent cancellation of deferred action. Here's a working example (the delay is 3 seconds). But when I choose to delete multiple items and cancel one of them, then canceled all at once.

史诗代码:

const itemsEpic = action$ =>
  action$.ofType('WILL_DELETE')
    .flatMap(action =>
      Observable.of({type: 'DELETE', id: action.id})
        .delay(3000)
        .takeUntil(action$.ofType('UNDO_DELETE'))
  )

我想我需要将 id 传递给 takeUntil 操作符,但我不知道该怎么做.

I think I need to pass an id to takeUntil operator, but I don't know how to do it.

推荐答案

如果我正确理解 takeUntil 运算符,它会停止从它被调用的 Observable 中发出新项目上,一旦参数 Observable 发出它的第一项.考虑到这一点,您可以执行以下操作:

If I understand the takeUntil operator correctly, it stops emitting new items from the Observable it was called on, once the argument Observable emits it's first item. With this in mind you could do something like this:

const itemsEpic = action$ => action$.ofType('WILL_DELETE')
  .flatMap(action => Observable.of({ type: 'DELETE', id: action.id })
    .delay(3000)
    .takeUntil(action$.ofType('UNDO_DELETE').filter(({id}) => id === action.id))
  )

这篇关于redux-observable 中的独立链取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆