https://github.com/richardcrng/redux-leaves
Write once. Reduce anywhere.
https://github.com/richardcrng/redux-leaves
javascript reducer redux state-management state-tree
Last synced: 6 months ago
JSON representation
Write once. Reduce anywhere.
- Host: GitHub
- URL: https://github.com/richardcrng/redux-leaves
- Owner: richardcrng
- Created: 2019-04-04T18:46:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:44:49.000Z (almost 3 years ago)
- Last Synced: 2025-03-28T18:51:39.814Z (7 months ago)
- Topics: javascript, reducer, redux, state-management, state-tree
- Language: TypeScript
- Homepage: https://redux-leaves.js.org
- Size: 17.8 MB
- Stars: 50
- Watchers: 3
- Forks: 4
- Open Issues: 37
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redux Leaves
Write once. Reduce anywhere.

[](https://coveralls.io/github/richardcrng/redux-leaves?branch=buttons)
[](https://badgen.net/bundlephobia/min/redux-leaves)
[](https://badge.fury.io/js/redux-leaves)## Example
```js
import { createStore } from 'redux'
import reduxLeaves, { bundle } from 'redux-leaves'// set up with initial state
const initialState = {
counter: 0,
list: [],
props: {}
}const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)// setup complete! Now dispatch actions to your heart's content
console.log(store.getState())
// => { counter: 0, list: [], props: {} }store.dispatch(actions.counter.create.increment(10))
console.log(store.getState())
// => { counter: 10, list: [], props: {} }store.dispatch(actions.list.create.push('foo'))
console.log(store.getState())
// => { counter: 10, list: ['foo'], props: {} }const compoundAction = bundle([
actions.counter.create.reset(),
actions.list[0].create.concat('bar'),
actions.props.at.arbitrary.path.create.update('here I am!')
])store.dispatch(compoundAction)
console.log(store.getState())
/*
=> {
counter: 0,
list: ['foobar'],
props: { at: { arbitrary: { path: 'here I am!' } } }
}
*/
```## Documentation
```bash
npm install --save redux-leaves
```[Main documentation website](https://redux-leaves.js.org)
### Getting started
- [Overview](https://redux-leaves.js.org/docs/intro/overview)
- [30 second demo](https://runkit.com/richardcrng/redux-leaves-playground/)### API reference
- [Core: `reduxLeaves(initialState, reducers)`](https://redux-leaves.js.org/docs/redux-leaves)### Testing
To run all tests locally:
```bash
git clone git@github.com:richardcrng/redux-leaves.git
cd redux-leaves && npm run test a
```Most tests are located alongside their relevant API documentation in the [docs](/docs) folder.