https://github.com/weavedev/redux-lazy
Quick save component for data storage in redux
https://github.com/weavedev/redux-lazy
Last synced: 5 months ago
JSON representation
Quick save component for data storage in redux
- Host: GitHub
- URL: https://github.com/weavedev/redux-lazy
- Owner: weavedev
- License: mit
- Created: 2020-01-15T14:58:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T14:58:42.000Z (over 3 years ago)
- Last Synced: 2025-10-25T04:26:39.245Z (8 months ago)
- Language: TypeScript
- Size: 550 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-lazy
[](https://github.com/weavedev/redux-lazy/blob/master/LICENSE)
[](https://www.npmjs.com/package/@weavedev/redux-lazy)
Quick save component for data storage in [Redux](http://redux.js.org/)
## Install
```
npm i @weavedev/redux-lazy
```
## API documentation
We generate API documentation with [TypeDoc](https://typedoc.org).
[](https://weavedev.github.io/redux-lazy/)
## Usage
### Creating
In this example we create a reducer and action to save an object to the store containing a message.
```ts
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.
```ts
import { message } from './message';
// If you are also using our store package (@weavedev/store)
window.store.dispatch(message.run({ message: 'Hey!' }));
```
## License
[GPL-3.0](https://github.com/weavedev/redux-lazy/blob/master/LICENSE)
Made by [Paul Gerarts](https://github.com/gerarts) and [Weave](https://weave.nl)