cute-redux
v1.0.1
Published
A tiny, minimal Redux-like state management library.
Downloads
185
Readme
cute-redux
Tiny Redux. Zero ceremony.
A minimal state container with just three ideas:
createStore(reducer, preloadedState)store.dispatch(action)store.subscribe(listener)+store.getState()
Quick Look
import Redux from "cute-redux";
const reducer = (state, action) => {
switch (action.type) {
case "INCREMENT":
return { ...state, count: state.count + 1 };
case "DECREMENT":
return { ...state, count: state.count - 1 };
default:
return state;
}
};
const store = Redux.createStore(reducer, { count: 0 });
const unsubscribe = store.subscribe(() => {
console.log(store.getState());
});
store.dispatch({ type: "INCREMENT" }); // { count: 1 }
unsubscribe();API
createStore(reducer, preloadedState) returns:
getState()dispatch(action)subscribe(listener)->unsubscribe()
Run Demo
From the repo root:
npm start