redux-observable 中的独立链取消?
Independent chain cancellation in redux-observable?
我是 RxJS 的新手。在我的应用程序中,我需要独立取消延迟操作。 Here's 一个工作示例(延迟为 3 秒)。但是当我选择删除多项并取消其中一项时,然后一次性全部取消。
史诗代码:
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
运算符,但我不知道该怎么做。
如果我正确理解 takeUntil
运算符,一旦参数 Observable
发出它的第一个项目,它就会停止从调用它的 Observable
发出新项目。考虑到这一点,您可以这样做:
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))
)
我是 RxJS 的新手。在我的应用程序中,我需要独立取消延迟操作。 Here's 一个工作示例(延迟为 3 秒)。但是当我选择删除多项并取消其中一项时,然后一次性全部取消。
史诗代码:
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
运算符,但我不知道该怎么做。
如果我正确理解 takeUntil
运算符,一旦参数 Observable
发出它的第一个项目,它就会停止从调用它的 Observable
发出新项目。考虑到这一点,您可以这样做:
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))
)