Skip to content

Instantly share code, notes, and snippets.

@stevermeister
Created May 18, 2017 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevermeister/4b515d5246ca90b66f0c701560a3c80a to your computer and use it in GitHub Desktop.
Save stevermeister/4b515d5246ca90b66f0c701560a3c80a to your computer and use it in GitHub Desktop.
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
let store = createStore(counter)
store.subscribe(() =>
console.log(store.getState())
)
store.dispatch({ type: 'INCREMENT' })
store.dispatch({ type: 'INCREMENT' })
store.dispatch({ type: 'DECREMENT' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment