@weavedev/redux-lazy
v0.1.11
Published
lazy function wrapper for redux powered by redux-saga
Downloads
85
Readme
redux-lazy
Quick save component for data storage in Redux
Install
npm i @weavedev/redux-lazy
API documentation
We generate API documentation with TypeDoc.
Usage
Creating
In this example we create a reducer and action to save an object to the store containing a message.
import { ReduxLazy } from '@weavedev/redux-lazy';
interface MyState {
message: string;
}
const SAVE_ACTION = 'SAVE_ACTION';
const defaultState: MyState = {
message: 'Hello!',
};
export const message = new ReduxLazy(SAVE_ACTION, defaultState);
// If you are also using our store package (@weavedev/store)
window.storeReducers.message = message.reducer;
declare global {
interface StoreReducersMap {
message: typeof message.reducer;
}
interface StoreActionsMap {
message: typeof message.actions;
}
}
Saving
You can update the state by calling .run()
. The argument type matches that of the default state provided in the constructor.
import { message } from './message';
// If you are also using our store package (@weavedev/store)
window.store.dispatch(message.run({ message: 'Hey!' }));
License
Made by Paul Gerarts and Weave