Skip to content

Commit f8f512b

Browse files
committed
Update README.md
1 parent 9e7deb4 commit f8f512b

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

README.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Read **[The Evolution of Flux Frameworks](https://medium.com/@dan_abramov/the-ev
2121

2222
## Demo
2323

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'>
2525

2626
```
2727
git clone https://github.com/gaearon/redux.git redux
@@ -84,36 +84,27 @@ import {
8484
DECREMENT_COUNTER
8585
} from '../constants/ActionTypes';
8686

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.
8889

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.
9093

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
10296
switch (action.type) {
10397
case INCREMENT_COUNTER:
104-
return increment(state, action);
98+
return counter + 1;
10599
case DECREMENT_COUNTER:
106-
return decrement(state, action);
100+
return counter - 1;
107101
default:
108-
return state;
102+
return counter;
109103
}
110104

111105
// BUT THAT'S A SWITCH STATEMENT!
112106
// Right. If you hate 'em, see the FAQ below.
113107
}
114-
115-
// bonus: no special support needed for ImmutableJS,
116-
// just return its objects as the state.
117108
```
118109

119110
### Components
@@ -247,9 +238,9 @@ export default function createStore(initialState, handlers) {
247238
and use it for your Stores:
248239

249240
```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
253244
});
254245
```
255246

0 commit comments

Comments
 (0)