kenichi-shibata
11/26/2015 - 1:29 AM

Redux Counter using store.dispatch store.subscribe (createStore) https://jsbin.com/voyehoq/edit?html,js,output

Redux Counter using store.dispatch store.subscribe (createStore) https://jsbin.com/voyehoq/edit?html,js,output

const counter = (state = 0, action) => {
  switch(action.type){
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
};
//created a basic counter using redux
const { createStore } = Redux;
// var createStore = Redux.createStore; //es5
// import { createStore } from 'redux' //babel import

const store = createStore(counter);
// created a new reducer using pure function counter

const render = () => {
    document.body.innerText = store.getState(); 
};
// get the state and put it in html body using render function

store.subscribe(render);
render();
// subscribe to render and run it once to get the initial state

document.addEventListener('click', () => {
  store.dispatch({type: 'INCREMENT'});
});