Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TapaniAla/fd15032773ac4ad98cc942b1b355ca35 to your computer and use it in GitHub Desktop.
Save TapaniAla/fd15032773ac4ad98cc942b1b355ca35 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const { createStore} = Redux;
const store = createStore(counter);
const render = () => {
document.body.innerText = store.getState();
}
// Needed to show initial state 0
store.subscribe(render);
// Needed to show initial state 0
render();
document.addEventListener('click', () => {
store.dispatch({type:'INCREMENT'});
});
'use strict';
var counter = function counter(state, action) {
if (state === undefined) state = 0;
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
var _Redux = Redux;
var createStore = _Redux.createStore;
var store = createStore(counter);
console.log(store.getState());
store.dispatch({ type: 'INCREMENT' });
console.log(store.getState());
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const { createStore} = Redux;
const store = createStore(counter);
store.subscribe(() => {
document.body.innerText = store.getState();
});
document.addEventListener('click', () => {
store.dispatch({type:'INCREMENT'});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment