是否可以在其他史诗 运行 时“跳过”执行?
Is it possible to `skip` execution while other epic is running?
我是 RxJS 的初学者,如果这没有意义,我深表歉意。
当前的时间流是这样的:
REMOVE_USER -----------------------> SUCCESS
---------------GET_DEVICE--->SUCCESS--------
high-level 目标是在删除用户时跳过获取设备。
过度简化epics:
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 的初学者,如果这没有意义,我深表歉意。
当前的时间流是这样的:
REMOVE_USER -----------------------> SUCCESS
---------------GET_DEVICE--->SUCCESS--------
high-level 目标是在删除用户时跳过获取设备。
过度简化epics:
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”中有更多关于暂停和静音流的信息。
--
希望对您有所帮助