Skip to content

Commit 5495a02

Browse files
committed
Updated Reducers docs.
1 parent ee689f9 commit 5495a02

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/Reducers.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Reducers
22

3-
Modules can implement a reducer. A reducer is a function that receives the current state and the action object, and returns the new state.
3+
A [reducer](http://redux.js.org/docs/basics/Reducers.html) is a function that receives the current state and an action, and returns the new state.
44

5-
A reducer is a pure function, this means it should do just one thing and it must be synchronous. Below is the simplest way of implementing a reducer:
5+
A reducer is a pure function, this means it should always return the same values whenever the same arguments are passed. So it can't depend on any external resource that can interfere in its return, like reading from a database. This also means that no side-effect, like updating the database, can be made in reducers.
6+
7+
From the Redux's docs, these are some of the things you should never do inside a reducer:
8+
9+
* Mutate its arguments;
10+
* Perform side effects like API calls and routing transitions;
11+
* Call non-pure functions, e.g. Date.now() or Math.random().
612

713
```js
814
const SAY_HELLO = 'mymodule/SAY_HELLO'
@@ -18,7 +24,8 @@ const mymodule = {
1824
}
1925
}
2026
```
21-
To reduce the need for multiple `if` or `switch` blocks you can use an object instead of a function for the reducer. This way you have multiple **action handlers** for each of the actions you want to listen to.
27+
28+
To avoid the need for multiple `if` or `switch` statements you can use an object instead of a function for the reducer. This way you have multiple action handlers, one for each of the actions you want to listen to.
2229

2330
```js
2431
const SAY_HELLO = 'mymodule/SAY_HELLO'
@@ -34,4 +41,4 @@ const mymodule = {
3441
}
3542
```
3643

37-
In the example above, the reducer object is passed to [redux-actions](https://github.com/acdlite/redux-actions) and then it's transformed to a single reducer. This removes the need to have control flow structures inside the reducer.
44+
In the example above, the reducer object is passed to [redux-actions](https://github.com/acdlite/redux-actions) and then it's transformed into a single reducer. This removes the need to have control flow structures inside the reducer.

0 commit comments

Comments
 (0)