Skip to content

Commit 168ccfa

Browse files
committed
Merge pull request reduxjs#527 from webpro/docs
Docs
2 parents c459ff9 + c12fb9e commit 168ccfa

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ npm install --save-dev redux-devtools
5252

5353
The whole state of your app is stored in an object tree inside a single *store*.
5454
The only way to change the state tree is to emit an *action*, an object describing what happened.
55-
To specify how the state tree is transformed by the actions, you write pure *reducers*.
55+
To specify how the actions transform the state tree, you write pure *reducers*.
5656

5757
That’s it!
5858

@@ -64,11 +64,11 @@ import { createStore } from 'redux';
6464
* It describes how an action transforms the state into the next state.
6565
*
6666
* The shape of the state is up to you: it can be a primitive, an array, an object,
67-
* or even an Immutable.js data structure. The only important part is you should
68-
* return a new object if the state changes, instead of mutating the parameter.
67+
* or even an Immutable.js data structure. The only important part is that you should
68+
* not mutate the state object, but return a new object if the state changes.
6969
*
7070
* In this example, we use a `switch` statement and strings, but you can use a helper that
71-
* follows a different convention (such as function maps) that makes sense for your project.
71+
* follows a different convention (such as function maps) if it makes sense for your project.
7272
*/
7373
function counter(state = 0, action) {
7474
switch (action.type) {
@@ -81,7 +81,7 @@ function counter(state = 0, action) {
8181
}
8282
}
8383

84-
// Create a Redux store that holds the state of your app.
84+
// Create a Redux store holding the state of your app.
8585
// Its API is { subscribe, dispatch, getState }.
8686
let store = createStore(counter);
8787

@@ -125,7 +125,7 @@ This architecture might seem like an overkill for a counter app, but the beauty
125125

126126
### Discussion
127127

128-
Join the **#redux** channel of the [Reactiflux](http://reactiflux.com/) Slack community.
128+
Join the **#redux** channel of the [Reactiflux](http://reactiflux.com) Slack community.
129129

130130
### Thanks
131131

@@ -140,7 +140,7 @@ Join the **#redux** channel of the [Reactiflux](http://reactiflux.com/) Slack co
140140
* [Cycle](https://github.com/staltz/cycle) for showing how often a function is the best tool;
141141
* [React](https://github.com/facebook/react) for the pragmatic innovation.
142142

143-
Special thanks to [Jamie Paton](http://jdpaton.github.io/) for handing over the `redux` NPM package name.
143+
Special thanks to [Jamie Paton](http://jdpaton.github.io) for handing over the `redux` NPM package name.
144144

145145
### Patrons
146146

docs/advanced/Middleware.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,7 @@ import { createStore, combineReducers, applyMiddleware } from 'redux';
316316

317317
// applyMiddleware takes createStore() and returns
318318
// a function with a compatible API.
319-
let createStoreWithMiddleware = applyMiddleware(
320-
logger,
321-
crashReporter
322-
)(createStore);
319+
let createStoreWithMiddleware = applyMiddleware(logger, crashReporter)(createStore);
323320

324321
// Use it like you would use createStore()
325322
let todoApp = combineReducers(reducers);

docs/introduction/Motivation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Motivation
22

3-
As the requirements to JavaScript single-page applications get more sophisticated, **more state than ever before needs to be managed by the JavaScript code.** This state may include server responses, cached data, and data created locally, but not yet persisted to the server. It also includes the UI state, such as the active route, the selected tab, whether to show a spinner or pagination controls, and so on.
3+
As the requirements to JavaScript single-page applications get more sophisticated, **more state needs to be managed** by the JavaScript code than ever before. This state may include server responses, cached data, and data created locally, but not yet persisted to the server. It also includes the UI state, such as the active route, the selected tab, whether to show a spinner or pagination controls, and so on.
44

55
Managing ever-changing state is hard. If a model can update another model, then a view can update a model that updates another model, and this, in turn, might cause another view to update. At some point you no longer know what happens in your app. **You no longer control when, why, and how the state is updated.** When the system is opaque and non-deterministic, it’s hard to reproduce bugs or add new features.
66

7-
As if this wasn’t bad enough, consider the **new requirements that are becoming common in front-end product development**, such as handling optimistic updates, rendering on the server, fetching the data before performing route transitions, and so on. We the front-end developers are finding ourselves surrounded by complexity we never had to deal with before. [Is it time we give up?](http://www.quirksmode.org/blog/archives/2015/07/stop_pushing_th.html)
7+
As if this wasn’t bad enough, consider the **new requirements becoming common in front-end product development**, such as handling optimistic updates, rendering on the server, fetching data before performing route transitions, and so on. We the front-end developers are finding ourselves surrounded by the complexity we never had to deal with before. [Is it time we give up?](http://www.quirksmode.org/blog/archives/2015/07/stop_pushing_th.html)
88

9-
A lot of this complexity comes from the fact that **we’re mixing two concepts that are very hard for the human mind to reason about: mutation and asynchronicity.** I call them [Mentos and Coke](https://en.wikipedia.org/wiki/Diet_Coke_and_Mentos_eruption). Both can be great in separation, but together, they are a mess. Libraries like [React](http://facebook.github.io/react) attempt to solve this problem in the view layer by removing asynchrony and direct DOM manipulation. However, React leaves managing the state of your data up to you.
9+
A lot of this complexity comes from the fact that **we’re mixing two concepts** that are very hard for the human mind to reason about: **mutation and asynchronicity.** I call them [Mentos and Coke](https://en.wikipedia.org/wiki/Diet_Coke_and_Mentos_eruption). Both can be great in separation, but together, they are a mess. Libraries like [React](http://facebook.github.io/react) attempt to solve this problem in the view layer by removing asynchrony and direct DOM manipulation. However, React leaves managing the state of your data up to you.
1010

1111
Following the steps of [Flux](http://facebook.github.io/flux), [CQRS](http://martinfowler.com/bliki/CQRS.html), and [Event Sourcing](http://martinfowler.com/eaaDev/EventSourcing.html), **Redux attempts to make state mutations predictable** by imposing certain restrictions on how and when updates can happen. These restrictions are reflected in the [three principles](ThreePrinciples.md) of Redux.

docs/introduction/ThreePrinciples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Redux can be described in three fundamental principles:
66

77
**The [state](../Glossary.md#state) of your whole application is stored in an object tree inside a single [store](../Glossary.md#store).**
88

9-
This makes it easy to create universal apps. The state from the server can be serialized and hydrated into the client with no extra coding effort. It is easier to debug an application when there is a single state tree. You can also persist your app’s state in development for a faster development cycle. And of course, with a single state tree, you get previously difficult functionality like Undo/Redo for free.
9+
This makes it easy to create universal apps. The state from the server can be serialized and hydrated into the client with no extra coding effort. It is easier to debug an application when there is a single state tree. You can also persist your app’s state in development for a faster development cycle. And with a single state tree, you get previously difficult functionality like Undo/Redo for free.
1010

1111
```js
1212
console.log(store.getState());
@@ -45,7 +45,7 @@ store.dispatch({
4545

4646
**To specify how the state tree is transformed by actions, you write pure [reducers](../Glossary.md#reducer).**
4747

48-
Reducers are just pure functions that take the previous state and an action, and return the next state. You can start with a single reducer, but as your app grows, you can split it into smaller reducers that manage specific parts of the state tree. Because reducers are just functions, you can control the order in which they are called, pass additional data, or even make reusable reducers for common tasks such as pagination.
48+
Reducers are just pure functions that take the previous state and an action, and return the next state. Remember to return new state objects, instead of mutating the previous state. You can start with a single reducer, but as your app grows, you can split it into smaller reducers that manage specific parts of the state tree. Because reducers are just functions, you can control the order in which they are called, pass additional data, or even make reusable reducers for common tasks such as pagination.
4949

5050
```js
5151
function visibilityFilter(state = 'SHOW_ALL', action) {

0 commit comments

Comments
 (0)