Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rameshanandakrishnan/5d2bbaf34627c1a99dcad0dd1b628e23 to your computer and use it in GitHub Desktop.
Save rameshanandakrishnan/5d2bbaf34627c1a99dcad0dd1b628e23 to your computer and use it in GitHub Desktop.
First react counter example without react
function counter(state, action) {
if (typeof state === 'undefined') {
return 0;
}
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT'){
return state -1;
}else {
return state;
}
}
var createStore = Redux.createStore;
var store = createStore(counter);
console.log(store.getState());
store.dispatch({ type: 'INCREMENT' });
console.log(store.getState());
var render = function(){
document.body.innerText = store.getState();
};
store.subscribe(render);
render();
document.addEventListener('click', function(){
store.dispatch({type: 'INCREMENT'});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment