housinganywhere / safe-redux Goto Github PK
View Code? Open in Web Editor NEWCreate and handle safely typed actions
License: MIT License
Create and handle safely typed actions
License: MIT License
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
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;
}
};
}```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.