Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commitca03df0

Browse files
committed
Update README
1 parent8a046af commitca03df0

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

‎README.md‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,61 @@
66
#Redux dynamics
77
Strongly-typed collection of useful methods and tools to make your[Redux](http://redux.js.org/) workflow more dynamic.
88

9+
##Features
10+
*`state` is always immutable
11+
*`action` is always immutable
12+
*`context` shared between all subscriptions
13+
* Declarative reducer subscriptions to the actions
14+
* Encouragement of pure resolver functions
15+
* Accept`RegExp` as subscribed action type
16+
***No huge`switch` statements anymore!**
17+
918
##Getting started
10-
Install`redux-dynamics` using npm:
11-
```basg
19+
20+
###Install
21+
22+
####NPM:
23+
```bash
1224
npm install redux-dynamics --save
1325
```
1426

15-
Include it in your project:
27+
####Yarn:
28+
```bash
29+
yarn add redux-dynamics
30+
```
31+
32+
###Create a reducer
33+
1634
```js
17-
/* ES5*/
18-
constreduxDynamics=require('redux-dynamics');
19-
constcreateReducer=require('redux-dynamics').createReducer;
35+
// store/comments/index.js
36+
import {Reducer }from'redux-dynamics';
2037

21-
/* ES6+*/
22-
importreduxDynamicsfrom'redux-dynamics';
23-
import {createReducer }from'redux-dynamics';
38+
/* Create a new reducer with initial state*/
39+
constreducer=newReducer({
40+
likes:0
41+
});
42+
43+
/* Subscribe to action types*/
44+
reducer.subscribe('ADD_LIKES', (state,action,context)=> {
45+
/* Note how both "state" and "action" are immutable*/
46+
constnextLikes=state.get('likes')+action.get('amount');
47+
48+
/* Resolve the next state*/
49+
returnstate.set('likes', nextLikes);
50+
});
2451
```
2552

26-
##Methods
27-
###`createReducer({ initialState?: State, actions: Array<ExpectedAction> })`
28-
####Features:
29-
* Simplified declaration of initial state
30-
* Enforced immutability of the`state` (using[Immutable](https://facebook.github.io/immutable-js))
31-
* Enforced immutability of the`action` for seamless integration with the state
32-
* Scoped variables and logic for reducer functions
33-
* Support of`RegExp` as an expected action type
34-
* No explicit state return, it is always returned by default
35-
36-
See[`createReducer` documentation](./docs/api/createReducer.md).
53+
###Connect to the Redux
54+
```js
55+
// store/reducer.js
56+
import {createReducer }from'redux';
57+
importcommentsReducerfrom'./comments';
58+
59+
exportdefaultcreateReducer({
60+
/* Convert "Reducer" class into pure function*/
61+
comments:commentsReducer.toFunction()
62+
});
63+
```
3764

3865
##Documentation
3966
For more details on methods, usage examples and troubleshooting[see the Documentation](./docs).

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp