Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created May 1, 2017 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdjkelly/c5de9fa7d662099b5d26b6a1163c50d3 to your computer and use it in GitHub Desktop.
Save jdjkelly/c5de9fa7d662099b5d26b6a1163c50d3 to your computer and use it in GitHub Desktop.
counter app
import { createStore } from 'redux'
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' })
// 1
store.dispatch({ type: 'INCREMENT' })
// 2
store.dispatch({ type: 'DECREMENT' })
// 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment