Created
May 1, 2017 00:43
-
-
Save jdjkelly/c5de9fa7d662099b5d26b6a1163c50d3 to your computer and use it in GitHub Desktop.
counter app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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