Skip to content

Commit b868ad7

Browse files
committed
Merge pull request reduxjs#489 from mindjuice/patch-7
Minor help text improvements
2 parents aa93a78 + 43d9828 commit b868ad7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/basics/Reducers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
## Designing the State Shape
66

7-
In Redux, all state of your application is stored as a single object. It’s a good idea to think of its shape before writing any code. What’s the minimal representation of your app’s state as an object?
7+
In Redux, all application state is stored as a single object. It’s a good idea to think of its shape before writing any code. What’s the minimal representation of your app’s state as an object?
88

99
For our todo app, we want to store two different things:
1010

1111
* The currently selected visibility filter;
1212
* The actual list of todos.
1313

14-
You’ll often find that you need to store some data, as well as some UI state, in the state tree. This is fine, but try to keep the data separately from the UI state.
14+
You’ll often find that you need to store some data, as well as some UI state, in the state tree. This is fine, but try to keep the data separate from the UI state.
1515

1616
```js
1717
{
@@ -28,11 +28,11 @@ You’ll often find that you need to store some data, as well as some UI state,
2828

2929
>##### Note on Relationships
3030
31-
>In a more complex app, you’re going to want different entities to reference each other. We suggest that you keep your state as normalized as possible, without any nesting. Keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists. Think of the app’s state as of a database. This approach is described in [normalizr](https://github.com/gaearon/normalizr) documentation in detail. For example, keeping `todosById: { id -> todo }` and `todos: array<id>` inside the state would be a better idea in a real app, but we’re keeping the example simple.
31+
>In a more complex app, you’re going to want different entities to reference each other. We suggest that you keep your state as normalized as possible, without any nesting. Keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists. Think of the app’s state as a database. This approach is described in [normalizr's](https://github.com/gaearon/normalizr) documentation in detail. For example, keeping `todosById: { id -> todo }` and `todos: array<id>` inside the state would be a better idea in a real app, but we’re keeping the example simple.
3232
3333
## Handling Actions
3434

35-
Now that we decided what our state object looks like, we are ready to write a reducer for it. The reducer is a pure function that takes the previous state and an action, and returns the next state.
35+
Now that we've decided what our state object looks like, we're ready to write a reducer for it. The reducer is a pure function that takes the previous state and an action, and returns the next state.
3636

3737
```js
3838
(previousState, action) => newState
@@ -95,7 +95,7 @@ function todoApp(state = initialState, action) {
9595

9696
Note that:
9797

98-
1. **We don’t mutate the `state`.** We create a copy with [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign). `Object.assign(state, ...)` is also wrong: it will mutate the first argument. You **must** supply an empty object as the first parameter. You can also enable the experimental [object spread syntax](https://github.com/sebmarkbage/ecmascript-rest-spread) proposed for ES7 to write `{ ...state, ...newState }` instead.
98+
1. **We don’t mutate the `state`.** We create a copy with [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign). `Object.assign(state, { visibilityFilter: action.filter })` is also wrong: it will mutate the first argument. You **must** supply an empty object as the first parameter. You can also enable the experimental [object spread syntax](https://github.com/sebmarkbage/ecmascript-rest-spread) proposed for ES7 to write `{ ...state, ...newState }` instead.
9999

100100
2. **We return the previous `state` in the `default` case.** It’s important to return the previous `state` for any unknown action.
101101

@@ -135,7 +135,7 @@ function todoApp(state = initialState, action) {
135135

136136
Just like before, we never write directly to `state` or its fields, and instead we return new objects. The new `todos` is equal to the old `todos` concatenated with a single new item at the end. The fresh todo was constructed using the data from the action.
137137

138-
Finally, the implementation of `COMPLETE_TODO` handler shouldn’t come as a complete surprise:
138+
Finally, the implementation of the `COMPLETE_TODO` handler shouldn’t come as a complete surprise:
139139

140140
```js
141141
case COMPLETE_TODO:

0 commit comments

Comments
 (0)