Lurker News

Comments (286) 115 threads

Earlier comments
robbick1 reply#
Can't say I've seen enough to be confident on the best library but redux (https://github.com/reduxjs/redux) is just so simple, and has great, readable/understandable code.
icc97#
In Dan Abramov's excellent egghead redux course [0] he implements the `createStore` from scratch which is the core of redux, it's simple enough to post here:

  const createStore = (reducer) => {
    let state;
    let listeners = [];

    const getState = () => state;

    const dispatch = (action) => {
        state = reducer(state, action);
        listeners.map(listener => listener());
    };

    const subscribe = (listener) => {
        listeners.push(listener);
        // unsubscribe
        return () => {
            listeners = listeners.filter(l => l !== listener)
        };
    };

    // populate initial state
    dispatch({});

    return { getState, dispatch, subscribe };
  };

[0]: https://egghead.io/lessons/react-redux-implementing-store-fr...
coldnose1 reply#
After spending about a month of concerted effort pouring through the zlib sources, looking for vulnerabilities, I can say that zlib is the most astonishingly bug-free code I've ever seen. But in the conventional understanding of "code quality", it's pretty bad.

Load more comments