Skip to content

Commit f779885

Browse files
SuaYootimche
authored andcommitted
Update docs with prefix and namespace example (#333)
* Update docs with `prefix` and `namespace` example Documents resolution in #263 * fix whitespace formatting in `createAction` docs * document options argument in `createActions` headlines * document options argument in `handleActions`
1 parent 448fa42 commit f779885

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

docs/api/createAction.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
- [`createAction(type, payloadCreator)`](#createactiontype-payloadcreator)
77
- [`createAction(type, payloadCreator, metaCreator)`](#createactiontype-payloadcreator-metacreator)
88
- [createActions](#createactions)
9-
- [`createActions(actionMap)`](#createactionsactionmap)
10-
- [`createActions(actionMap, ...identityActions)`](#createactionsactionmap-identityactions)
9+
- [`createActions(actionMap[, options])`](#createactionsactionmap)
10+
- [`createActions(actionMap, ...identityActions[, options])`](#createactionsactionmap-identityactions)
1111

1212
## Methods
1313

@@ -137,6 +137,7 @@ updateAdminUser({ name: 'Foo' });
137137
createActions(
138138
actionMap,
139139
?...identityActions,
140+
?options
140141
)
141142
```
142143
@@ -146,7 +147,7 @@ Returns an object mapping action types to action creators. The keys of this obje
146147
import { createActions } from 'redux-actions';
147148
```
148149
149-
#### `createActions(actionMap)` {#createactionsactionmap}
150+
#### `createActions(actionMap[, options])` {#createactionsactionmap}
150151
151152
`actionMap` is an object which can optionally have a recursive data structure, with action types as keys, and whose values **must** be either
152153
@@ -208,15 +209,7 @@ expect(
208209
});
209210
```
210211
211-
When using this form, you can pass an object with key `namespace` as the last positional argument (the default is `/`).
212-
213-
###### EXAMPLE
214-
215-
```js
216-
createActions({ ... }, 'INCREMENT', { namespace: '--' })
217-
```
218-
219-
#### `createActions(actionMap, ...identityActions)`{#createactionsactionmap-identityactions}
212+
#### `createActions(actionMap, ...identityActions[, options])`{#createactionsactionmap-identityactions}
220213
221214
`identityActions` is an optional list of positional string arguments that are action type strings; these action types will use the identity payload creator.
222215
@@ -253,3 +246,18 @@ expect(actionThree(3)).to.deep.equal({
253246
payload: 3
254247
});
255248
```
249+
250+
#### `createActions(actionMap[, ...identityActions], options)`
251+
252+
You can prefix each action type by passing a configuration object as the last argument of `createActions`.
253+
254+
###### EXAMPLE
255+
256+
```js
257+
createActions({ ... }, 'INCREMENT', {
258+
prefix: 'counter', // String used to prefix each type
259+
namespace: '--' // Separator between prefix and type. Default: `/`
260+
})
261+
```
262+
263+
`'INCREMENT'` in this example will be prefixed as `counter--INCREMENT`.

docs/api/handleAction.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- [`handleAction(type, reducer, defaultState)`](#handleactiontype-reducer-defaultstate)
66
- [`handleAction(type, reducerMap, defaultState)`](#handleactiontype-reducermap-defaultstate)
77
- [handleActions](#handleactions)
8-
- [`handleActions(reducerMap, defaultState)`](#handleactionsreducermap-defaultstate)
8+
- [`handleActions(reducerMap, defaultState[, options])`](#handleactionsreducermap-defaultstate)
99

1010
## Methods
1111

@@ -70,13 +70,13 @@ handleActions(reducerMap, defaultState);
7070

7171
Creates multiple reducers using `handleAction()` and combines them into a single reducer that handles multiple actions. Accepts a map where the keys are passed as the first parameter to `handleAction()` (the action type), and the values are passed as the second parameter (either a reducer or reducer map). The map must not be empty.
7272

73-
If `reducerMap` has a recursive structure, its leaves are used as reducers, and the action type for each leaf is the path to that leaf. If a node's only children are `next()` and `throw()`, the node will be treated as a reducer. If the leaf is `undefined` or `null`, the identity function is used as the reducer. Otherwise, the leaf should be the reducer function. When using this form, you can pass an object with key `namespace` as the last positional argument (the default is `/`).
73+
If `reducerMap` has a recursive structure, its leaves are used as reducers, and the action type for each leaf is the path to that leaf. If a node's only children are `next()` and `throw()`, the node will be treated as a reducer. If the leaf is `undefined` or `null`, the identity function is used as the reducer. Otherwise, the leaf should be the reducer function.
7474

7575
```js
7676
import { handleActions } from 'redux-actions';
7777
```
7878

79-
#### `handleActions(reducerMap, defaultState)` {#handleactionsreducermap-defaultstate}
79+
#### `handleActions(reducerMap, defaultState[, options])` {#handleactionsreducermap-defaultstate}
8080

8181
The second parameter `defaultState` is required, and is used when `undefined` is passed to the reducer.
8282

@@ -147,3 +147,20 @@ const reducer = handleActions(
147147
{ counter: 0 }
148148
);
149149
```
150+
151+
#### `handleActions(actionMap[, defaultState], options)`
152+
153+
You can prefix each action type by passing a configuration object as the last argument of `handleActions`.
154+
155+
###### EXAMPLE
156+
157+
```js
158+
const options = {
159+
prefix: 'counter', // String used to prefix each type
160+
namespace: '--' // Separator between prefix and type. Default: `/`
161+
}
162+
163+
createActions({ ... }, 'INCREMENT', options)
164+
165+
handleActions({ ... }, defaultState, options)
166+
```

0 commit comments

Comments
 (0)