Giter Site home page Giter Site logo

safe-redux's People

Contributors

gillchristian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

safe-redux's Issues

Critical dependency warning

Webpack gives the following warning

WARNING in ./node_modules/@gillchristian/safe-redux/dist/umd/index.js 3:24-31
    Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Support for Immer

Immer is a library that allows a developer to work on a draft of state instead of recreating the state for each handled action.

An example of a reducer:

import produce from "immer"

const baseState = [
    {
        todo: "Learn typescript",
        done: true
    },
    {
        todo: "Try immer",
        done: false
    }
];

const nextState = produce(baseState, draftState => {
    draftState.push({todo: "Tweet about it"})
    draftState[1].done = true
});

It would be nice to support this in safe-redux. The changes are quite simple, but the major question is how we support that inside this package. for example, an immer implementation of Handler could be changed to:

export type Handler<State, ActionType extends string, Actions> = (
  draft: Draft<State>,
  state: State,
  action: ActionsOfType<Actions, ActionType>,
) => State;

Where we introduce the draft that is mutable and part of immer. At the same time, we need to have an implementation of handleActions that looks something like this:

export function handleActions<
  State,
  Types extends string,
  Actions extends ActionsUnion<{ [T in Types]: ActionCreator }>
>(handlers: { [T in Types]: Handler<State, T, Actions> }, initialState: State) {
  return (state = initialState, action: Actions): State => {
    return produce(state, draft => {
        const handler = handlers[action.type];
        return handler ? handler(state, action) : state;
    }
  };
}```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.