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

查看:121
本文介绍了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天全站免登陆