1
1
# ` redux-immutablejs `
2
2
3
- An alternative to [ combineReducers] ( http://rackt.github.io/redux/docs/api/combineReducers.html ) that supports
4
- [ ImmutableJs] ( https://facebook.github.io/immutable-js/ ) .
3
+ Redux & Immutable integration
4
+
5
+ This is a small library that aims to provide integration tools between [ Redux] ( https://github.com/rackt/redux )
6
+ & [ ImmutableJs] ( https://facebook.github.io/immutable-js/ ) that fully conforms Redux _ actions_ & _ reducers_ standards.
7
+
8
+ 1 . An alternative to [ combineReducers] ( http://rackt.github.io/redux/docs/api/combineReducers.html ) that supports
9
+ [ ImmutableJs] ( https://facebook.github.io/immutable-js/ ) for store initial state.
10
+ 1 . An optional handler map reducer creator with immutable support.
11
+
5
12
6
13
# Setup
7
14
@@ -23,6 +30,36 @@ const state = reducer(state);
23
30
export default createStore (reducer, state);
24
31
```
25
32
33
+ ## Immutable Handler Map reducer creator
34
+
35
+ Using ` createReducer ` is an optional function that creates a reducer from a collection of handlers, except
36
+ getting ride of the _ switch_ statement, it also provides the following benefits:
37
+
38
+ 1 . If the given ` initialState ` type is mutated, it will get converted to an immutable type.
39
+ 1 . An error is produced in case a reducer handler returns a mutated state (not recommended but this behavior can be disabled)
40
+
41
+ ``` js
42
+ import { createReducer } from ' redux-immutablejs'
43
+ const initialState = Immutable .fromJS ({ isAuth: false })
44
+
45
+ /**
46
+ * Reducer domain that handles authentication & authorization.
47
+ **/
48
+ export default createReducer (initialState, {
49
+ [LOGIN ] (state , action ) {
50
+ return state .merge ({ ' isAuth' : true , token: action .payload .token })
51
+ },
52
+
53
+ [LOGOUT ] (domain ) {
54
+ return domain .merge ({ ' isAuth' : false , ' current_identity' : {}, token: undefined })
55
+ }
56
+ })
57
+ ```
58
+
59
+
60
+ Please note that this is optional and ` combineReducers ` should work just fine if you prefer the old ` switch ` way.
61
+
62
+
26
63
# FAQ
27
64
28
65
## How this library is different from 'redux-immutable' ?
0 commit comments