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

redux basics from https://jsbin.com/fizibo/edit?js,console

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);
console.log(store.getState());
// created a new reducer using pure function counter

store.dispatch({type: 'INCREMENT' });
console.log(store.getState());

store.dispatch({type: 'DECREMENT'});
console.log(store.getState());

store.dispatch({type: 'DECREMENT'});
console.log(store.getState());

store.dispatch({type: 'INCREMENT' });
console.log(store.getState());

store.dispatch({type: 'INCREMENT' });
console.log(store.getState());

store.dispatch({type: 'INCREMENT' });
console.log(store.getState());

// redux does not set State it returns the state to its original state after execution (immutable)

// of course you need to add redux dependencies