问题描述
我想通过调用 actions.blinkingClockAction() 将我的状态值之一从真、假、真切换到真。所以我试图在我的 observable 中连续调用相同的动作。似乎动作只能被调用一次或只能被接收一次。我是 observables 的新手,所以如果你能解释为什么那会很棒。
可观察:
const someEpic$: Epic<AnyAction,AnyAction,ReducerState | any,Services> = (
action$,state$,{ AlarmClock }
) =>
action$.pipe(
filter(isActionOf(actions.resetClockAction)),map(() => actions.blinkingClockAction()),delay(1000),map(() => actions.restartClockAction()),tap((val) => console.log(val))
);
减速器:
export const firstReducer: Reducer<typeof initialState,ReducerActions> = (
state = initialState,action: ReducerActions
) => {
switch (action.type) {
case getType(actions.pauseAction):
return { ...state,timeRunning: !state.timeRunning };
case getType(actions.resetClockAction):
return {
...state,currentTime: new Date().toLocaleTimeString("en-US"),timeRunning: false,showing: false,};
case getType(actions.runclockAction):
if (state.timeRunning) {
return { ...state,currentTime: new Date().toLocaleTimeString("en-US") };
} else {
return state;
}
case getType(actions.blinkingClockAction):
return { ...state,showing: !state.showing };
case getType(actions.restartClockAction):
return { ...state,timeRunning: true };
default:
return state;
}
};
动作:
import { ActionType } from "typesafe-actions";
import { createAction } from "typesafe-actions";
export const pauseAction = createAction("PAUSE_TIME")();
export const runclockAction = createAction("RUN_CLOCK")();
export const resetClockAction = createAction("RESET_CLOCK")();
export const restartClockAction = createAction("RESTART_CLOCK")();
export const blinkingClockAction = createAction("BLINKING_CLOCK")();
export const actions = {
pauseAction,runclockAction,resetClockAction,restartClockAction,blinkingClockAction,
};
导出类型 Action = ActionType;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)