【发布时间】:2021-01-11 14:29:45
【问题描述】:
假设这个演示代码:
const pingEpic = action$ => action$.pipe(
filter(action => action.type === 'PING'),
delay(1000), // Asynchronously wait 1000ms then continue
mapTo({ type: 'PONG' })
);
// later...
dispatch({ type: 'PING' });
const pingReducer = (state = {}, action) => {
switch (action.type) {
case 'PING':
return state;
case 'PONG':
return state;
default:
return state;
}
};
在一个特定的组件中,假设与调度 PING 或 PONG 无关,也不使用任何 redux 状态,我想以某种方式订阅操作生命周期以及 PONG 操作何时完成(即已被减速器处理) 它执行一个回调。比如:
const myComponent = () => {
ofActionSuccessful('PONG').subscribe( () => console.log('PONG has just completed'));
}
类似:https://www.ngxs.io/advanced/action-handlers
我怎样才能做到这一点?
我不想在reducer中链接一些逻辑,因为它是与那个组件严格相关的东西,与store无关。
【问题讨论】:
标签: reactjs redux rxjs redux-observable