@@ -21,7 +21,7 @@ Read **[The Evolution of Flux Frameworks](https://medium.com/@dan_abramov/the-ev
21
21
22
22
## Demo
23
23
24
- ![ gif ] ( https://s3.amazonaws.com/f.cl.ly/items/2Z2D3U260d2A311k2B0z/Screen%20Recording%202015-06-03%20at%2003.22%20pm.gif )
24
+ < img src = ' https://s3.amazonaws.com/f.cl.ly/items/2Z2D3U260d2A311k2B0z/Screen%20Recording%202015-06-03%20at%2003.22%20pm.gif ' width = ' 500 ' >
25
25
26
26
```
27
27
git clone https://github.com/gaearon/redux.git redux
@@ -84,36 +84,27 @@ import {
84
84
DECREMENT_COUNTER
85
85
} from ' ../constants/ActionTypes' ;
86
86
87
- // but you can write this part anyhow you like:
87
+ // what's important is that Store is a pure function,
88
+ // and you can write it anyhow you like.
88
89
89
- const initialState = 0 ;
90
+ // the Store signature is (state, action) => state,
91
+ // and the state shape is up to you: you can use primitives,
92
+ // objects, arrays, or even ImmutableJS objects.
90
93
91
- function increment (counter ) {
92
- return counter + 1 ;
93
- }
94
-
95
- function decrement (counter ) {
96
- return counter - 1 ;
97
- }
98
-
99
- // what's important is that Store is a pure function too
100
- export default function counterStore (state = initialState , action ) {
101
- // that returns the new state when an action comes
94
+ export default function counterStore (counter = 0 , action ) {
95
+ // this function returns the new state when an action comes
102
96
switch (action .type ) {
103
97
case INCREMENT_COUNTER :
104
- return increment (state, action) ;
98
+ return counter + 1 ;
105
99
case DECREMENT_COUNTER :
106
- return decrement (state, action) ;
100
+ return counter - 1 ;
107
101
default :
108
- return state ;
102
+ return counter ;
109
103
}
110
104
111
105
// BUT THAT'S A SWITCH STATEMENT!
112
106
// Right. If you hate 'em, see the FAQ below.
113
107
}
114
-
115
- // bonus: no special support needed for ImmutableJS,
116
- // just return its objects as the state.
117
108
```
118
109
119
110
### Components
@@ -247,9 +238,9 @@ export default function createStore(initialState, handlers) {
247
238
and use it for your Stores:
248
239
249
240
``` js
250
- export default createStore (initialState , {
251
- [INCREMENT_COUNTER ]: increment ,
252
- [DECREMENT_COUNTER ]: decrement
241
+ export default createStore (0 , {
242
+ [INCREMENT_COUNTER ]: x => x + 1 ,
243
+ [DECREMENT_COUNTER ]: x => x - 1
253
244
});
254
245
```
255
246
0 commit comments