Created
November 12, 2017 03:13
-
-
Save renatoalencar/f5962f8ba9058102ec5ab8c63b78478a to your computer and use it in GitHub Desktop.
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
const { createStore } = Redux; | |
/* Action creators */ | |
function increment() { | |
return { | |
type: 'INCREMENT' | |
}; | |
} | |
function decrement() { | |
return { | |
type: 'DECREMENT' | |
}; | |
} | |
/* Reducer */ | |
function counter(state = 0, action) { | |
switch(action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} | |
/* Store */ | |
const store = createStore(counter); | |
/* View */ | |
store.subscribe(() => { | |
console.log(store.getState()); | |
}); | |
/* Execução */ | |
store.dispatch(increment()); | |
store.dispatch(increment()); | |
store.dispatch(decrement()); | |
store.dispatch(increment()); | |
store.dispatch(increment()); | |
store.dispatch(decrement()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment