// action that is fired at every tick export function tickCountdown() { return { type: types.TICK_COUNTDOWN }; } export function setTimerAction(handlerProp, action) { return (dispatch, getState) => { // dispatch an action to set the timer for `handlerProp` dispatch({ type: types.SET_TIMER, handlerProp }); // assume this is a Timer that calls passed callback at 1 sec interval new Timer(() => { const isContinue = getState()['timerStore'].get(handlerProp); if (isContinue) { const a = action(); dispatch(a); } return isContinue; }).start(); } } export function clearTimerAction(handlerProp) { return { type: types.CLEAR_TIMER, handlerProp } } /// call this somewhere proper to start the countdown /// possibly within another action setTimerAction('countdownTimer', tickCountdown); // possible to setup multiple timers with different names setTimerAction('countdownTimer2', tickCountdown);