Redux
Teste Redux
by Rafael Nepomuceno
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.6.0/redux.js"></script>
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
JavaScript
// Reducers
function reducers(state = 0, action) {
if(action.type == 'INCREMENTO') {
return state + 1;
}
if(action.type == 'DECREMENTO') {
return state - 1;
}
return state;
}
// Criar Store
let store = Redux.createStore(reducers);
// recuperar estado
console.log(store.getState());
//
store.dispatch({ type: 'INCREMENTO' });
console.log(store.getState());
store.dispatch({ type: 'DECREMENTO' });
console.log(store.getState());