Comparing version 0.0.13 to 1.0.0
{ | ||
"name": "repatch", | ||
"version": "0.0.13", | ||
"version": "1.0.0", | ||
"description": "Dispatch reducers", | ||
@@ -5,0 +5,0 @@ "main": "lib/store/index", |
@@ -5,7 +5,7 @@ # Repatch | ||
The most of redux projects do not need sctrict action administration. Action types, action creators and reducers' action handlers are mutually assigned to each other. | ||
[Redux](https://www.npmjs.com/package/redux) has a verbose action management. The most of redux projects do not need sctrict action administration. Action types, action creators and the reducer's action handlers are mutually assigned to each other. Repatch's purpose is creating actions briefly. | ||
The simplest way to keep immutable action controlled dataflow is dispatching pure functions (as reducers) to the store. | ||
So we have only actions which return reducers. | ||
In this terminology action is a function that returns a reducer. | ||
@@ -20,2 +20,8 @@ ```javascript | ||
Following this thread an inline action looks like this: | ||
```javascript | ||
dispatch(state => ({ ...state, isFetching: true })) | ||
``` | ||
## Installation | ||
@@ -27,2 +33,7 @@ | ||
## Examples | ||
- [JavaScript example](https://github.com/jaystack/repatch-example-electron-app) | ||
- [TypeScript example](https://github.com/jaystack/repatch-example-electron-app-ts) | ||
## How to use | ||
@@ -52,34 +63,18 @@ | ||
## Subreducers | ||
## Sub-reducers | ||
We do not need to reduce always the whole state of the store. A good practice to avoid this effort is using subreducers. | ||
We do not need to reduce always the whole state of the store. A good practice to avoid this effort is using sub-reducers. | ||
Let's suppose we have the following state: | ||
```javascript | ||
const store = new Store({ | ||
userManagement: { | ||
users: [...], | ||
isFetching: false, | ||
error: null | ||
const reduceFoo = reducer => state => ({ | ||
...state, | ||
bar: { | ||
...state.bar, | ||
foo: reducer(state.bar.foo) | ||
} | ||
}); | ||
``` | ||
Then we can make a subredcer for the `userManagement` section: | ||
```javascript | ||
const reduceUserManagement = reducer => state => ({ | ||
...state, | ||
userManagement: reducer(state.userManagement) | ||
}); | ||
const fooAction = payload => reduceFoo(state => ({ ...state, ...payload })); | ||
``` | ||
After that reducing only the `userManagement` state it's easy: | ||
```javascript | ||
const rejectFetchingUsers = error => | ||
reduceUserManagement(state => ({ ...state, error, isFetching: false })); | ||
``` | ||
## Middlewares | ||
@@ -167,5 +162,7 @@ | ||
const state = { name: 'hello' }; | ||
const nextState = changeName('hi')(state); | ||
assert.strictEqual(nextState.name, 'hi'); | ||
it('changeName', () => { | ||
const state = { name: 'john' }; | ||
const nextState = changeName('jack')(state); | ||
assert.strictEqual(nextState.name, 'jack'); | ||
}); | ||
``` | ||
@@ -172,0 +169,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13540
1
189