我是 RxJS 的初学者,如果这没有意义,我很抱歉。
当前的时间流动如下所示:
REMOVE_USER -----------------------> SUCCESS
---------------GET_DEVICE--->SUCCESS--------
高级目标是在删除用户时跳过获取设备。
过于简单化的史诗:
const getDeviceEpic = action$ => action$.pipe(
ofType('GET_DEVICE_REQUEST'),
mergeMap(() => from(service...).pipe(
mapTo({ type: 'GET_DEVICE_SUCCESS' }))
))
const removeUser = action$ => action$.pipe(
ofType('REMOVE_USER_REQUEST'),
mergeMap(() => from(service...).pipe(
mapTo({ type: 'REMOVE_USER_SUCCESS' }))
)
)
我将如何处理这个问题?
我不确定是否可以添加例如takeUntil(removeUserAPICall$)
到设备应用。或者也许检查 REMOVE_USER_REQUEST
是否已被触发,然后等待 REMOVE_USER_SUCCESS
继续。
最佳答案
有可能,您可以通过 windowToggle 来实现这一目标:
在您的情况下,“on”是REMOVE_USER_SUCCESS
,“off”是REMOVE_USER_REQUEST
。
因此,我们将在 REMOVE_USER_SUCCESS
和 REMOVE_USER_REQUEST
之间监听 GET_DEVICE_REQUEST
。
请注意,我们必须在打开过滤器的情况下开始,方法是将 startWith(void 0)
添加到“on”流。
例如:
const getDeviceEpic = action$ => action$.pipe(
ofType('GET_DEVICE_REQUEST'),
windowToggle(
action$.pipe(ofType('REMOVE_USER_SUCCESS'), startWith(void 0)),
()=>action$.pipe(ofType('REMOVE_USER_REQUEST')
),
mergeMap(() => from(service...).pipe(
mapTo({ type: 'GET_DEVICE_SUCCESS' }))
))
const removeUser = action$ => action$.pipe(
ofType('REMOVE_USER_REQUEST'),
mergeMap(() => from(service...).pipe(
mapTo({ type: 'REMOVE_USER_SUCCESS' }))
)
)
* 警告:用记事本编写
但是,恕我直言,在商店上挂一面旗帜也很好(也许,作为国家的指示)。
有关暂停和静音流的更多信息,请参阅我的文章“Pausable Observables in RxJS”。
--
希望这有帮助
关于rxjs - 当其他史诗正在运行时是否可以执行 `skip` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55967638/