Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux/React tutorial sans ES6?

Tags:

reactjs

redux

Does anyone know of a React & Redux tutorial that doesn't depend on ES6/2015?

It's difficult to attempt to learn a complex idea like Redux, let alone search for 'redux react tutorial without ES6' on Google. Please don't say 'just learn ES6...' Yes, I know.

Thank you!

like image 957
tedwards947 Avatar asked Mar 13 '16 00:03

tedwards947


1 Answers

Redux is not a complicated idea. It can be expressed in very few lines of code:

function createStore(reducer, state) {
  var listeners = [];
  var currentState = state;

  function subscribe(listener) {
    listeners.push(listener);
    return function unsubscribe() {
      listeners = listeners.splice(listeners.indexOf(listener), 1);
    };
  }

  function getState() {
    return state;
  }

  function dispatch(action) {
    currentState = reducer(currentState, action);
    for (var i = 0; i < listeners.length; ++i) {
      listeners[i]();
    }
  }

  return {
    getState: getState,
    subscribe: subscribe,
    dispatch: dispatch
  };
}

That's the basic idea. Of course, the actual library has a ton of sanity checks and additional validation, and adds extra things like middleware and store enhancers and such, but the core is as above.

What you really want is a basic React tutorial without all the extra stuff, and for that I would highly recommend James Knelson's excellent tutorial.

like image 163
rossipedia Avatar answered Oct 24 '22 10:10

rossipedia