Skip to content

Instantly share code, notes, and snippets.

@Meshugah
Created August 20, 2020 12:11
Show Gist options
  • Save Meshugah/993201a4a831c009c871e60614229547 to your computer and use it in GitHub Desktop.
Save Meshugah/993201a4a831c009c871e60614229547 to your computer and use it in GitHub Desktop.
const {createStore} = require('redux')
// Actions are mapped to state here, called a Reducer
function setIntervalState(state= 0, action) {
switch(action.type){
case 'START_TIMER':
return state = action.payload
case 'STOP_TIMER':
if(state !== 0)
clearInterval(state)
default:
break;
}
}
let store = createStore(setIntervalState)
// Actions
store.dispatch({type:'STOP_TIMER'})
let payload = setInterval(() => {
console.log("SHOULD NOT pause for 2 seconds")
}, 2000);
store.dispatch({type:'START_TIMER', payload: payload})
store.dispatch({type:'STOP_TIMER'})
payload = setInterval(() => {
console.log("SHOULD pause for 3 seconds")
}, 3000);
store.dispatch({type:'START_TIMER', payload: payload})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment