Skip to content

Commit 40ba754

Browse files
committed
Merge pull request reduxjs#517 from mindjuice/patch-22
Minor help text improvements
2 parents a918cd8 + bf09657 commit 40ba754

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docs/api/applyMiddleware.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
Middleware is the suggested way to extend Redux with custom functionality. Middleware lets you wrap the store’s [`dispatch`](Store.md#dispatch) method for fun and profit. The key feature of middleware is that it is composable. Multiple middleware can be combined together, where each middleware requires no knowledge of what comes before or after it in the chain.
44

5-
The most common use case for the middleware is to support asynchronous actions without much boilerplate code or a dependency on a library like [Rx](https://github.com/Reactive-Extensions/RxJS). It does so by letting you dispatch [async actions](../Glossary.md#async-action) in addition to normal actions.
5+
The most common use case for middleware is to support asynchronous actions without much boilerplate code or a dependency on a library like [Rx](https://github.com/Reactive-Extensions/RxJS). It does so by letting you dispatch [async actions](../Glossary.md#async-action) in addition to normal actions.
66

77
For example, [redux-thunk](https://github.com/gaearon/redux-thunk) lets the action creators invert control by dispatching functions. They would receive [`dispatch`](Store.md#dispatch) as an argument and may call it asynchronously. Such functions are called *thunks*. Another example of middleware is [redux-promise](https://github.com/acdlite/redux-promise). It lets you dispatch a [Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) async action, and dispatches a normal action when the Promise resolves.
88

99
Middleware is not baked into [`createStore`](createStore.md) and is not a fundamental part of the Redux architecture, but we consider it useful enough to be supported right in the core. This way, there is a single standard way to extend [`dispatch`](Store.md#dispatch) in the ecosystem, and different middleware may compete in expressiveness and utility.
1010

1111
#### Arguments
1212

13-
* `...middlewares` (*arguments*): Functions that conform to the Redux *middleware API*. Each middleware receives [`Store`](Store.md)’s [`dispatch`](Store.md#dispatch) and [`getState`](Store.md#getState) functions as named arguments, and returns a function. That function will be given the `next` middleware’s dispatch method, and is expected to return a function of `action` calling `next(action)` with a potentially different argument, or at a different time, or maybe not calling it at all. The last middleware in chain will receive the real store’s [`dispatch`](Store.md#dispatch) method as the `next` parameter, thus closing the chain. So, the middleware signature is `({ getState, dispatch }) => next => action`.
13+
* `...middlewares` (*arguments*): Functions that conform to the Redux *middleware API*. Each middleware receives [`Store`](Store.md)’s [`dispatch`](Store.md#dispatch) and [`getState`](Store.md#getState) functions as named arguments, and returns a function. That function will be given the `next` middleware’s dispatch method, and is expected to return a function of `action` calling `next(action)` with a potentially different argument, or at a different time, or maybe not calling it at all. The last middleware in the chain will receive the real store’s [`dispatch`](Store.md#dispatch) method as the `next` parameter, thus ending the chain. So, the middleware signature is `({ getState, dispatch }) => next => action`.
1414

1515
#### Returns
1616

@@ -62,7 +62,7 @@ function withdrawMoney(amount) {
6262
};
6363
}
6464

65-
// Even without a middleware, you can dispatch an action:
65+
// Even without middleware, you can dispatch an action:
6666
store.dispatch(withdrawMoney(100));
6767

6868
// But what do you do when you need to start an asynchronous action,
@@ -86,7 +86,7 @@ function makeASandwichWithSecretSauce(forPerson) {
8686
};
8787
}
8888

89-
// Thunk middleware let me dispatch thunk async actions
89+
// Thunk middleware lets me dispatch thunk async actions
9090
// as if they were actions!
9191

9292
store.dispatch(
@@ -137,9 +137,8 @@ function makeSandwichesForEverybody() {
137137
};
138138
}
139139

140-
// This is very useful for server rendering,
141-
// because I can wait to prefill the data before
142-
// sending synchronously rendering the app.
140+
// This is very useful for server side rendering, because I can wait
141+
// until data is available, then synchronously render the app.
143142

144143
store.dispatch(
145144
makeSandwichesForEverybody()
@@ -148,7 +147,7 @@ store.dispatch(
148147
);
149148

150149
// I can also dispatch a thunk async action from a component
151-
// any times its props change to load the missing data.
150+
// any time its props change to load the missing data.
152151

153152
import { connect } from 'react-redux';
154153
import { Component } from 'react';
@@ -223,4 +222,4 @@ store.dispatch({
223222

224223
* Ever wondered what `applyMiddleware` itself is? It ought to be an extension mechanism more powerful than the middleware itself. Indeed, `applyMiddleware` is an example of the most poweful Redux extension mechanism called [store enhancers](../Glossary.md#store-enhancer). It is highly unlikely you’ll ever want to write a store enhancer yourself. Another example of a store enhancer is [redux-devtools](https://github.com/gaearon/redux-devtools). Middleware is less powerful than a store enhancer, but it is easier to write.
225224

226-
* Middleware sounds much more complicated than it really is. The only way to really understand the middleware is to see how the existing middleware works, and try to write your own. The function nesting can be intimidating, but most of the middleware you’ll find are in fact 10-liners, and the nesting and composability is what makes the middleware system powerful.
225+
* Middleware sounds much more complicated than it really is. The only way to really understand middleware is to see how the existing middleware works, and try to write your own. The function nesting can be intimidating, but most of the middleware you’ll find are, in fact, 10-liners, and the nesting and composability is what makes the middleware system powerful.

0 commit comments

Comments
 (0)