Skip to content

Commit 5076200

Browse files
committed
Flesh out configureStore docs, and tweak other pages
1 parent f5a756f commit 5076200

File tree

4 files changed

+125
-25
lines changed

4 files changed

+125
-25
lines changed

docs/api/configureStore.md

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,78 @@ hide_title: true
77

88
# `configureStore`
99

10-
A friendlier abstraction over the standard Redux `createStore` function. Takes a single configuration object parameter, with the following options:
10+
A friendlier abstraction over the standard Redux `createStore` function.
11+
12+
13+
## Parameters
14+
15+
`configureStore` accepts a single configuration object parameter, with the following options:
1116

1217
```ts
1318
function configureStore({
1419
// A single reducer function that will be used as the root reducer,
1520
// or an object of slice reducers that will be passed to combineReducers()
16-
reducer: Object<string, Function> | Function,
17-
// An array of Redux middlewares. If not supplied, adds the middleware returned by getDefaultMiddleware()
18-
middleware: Array<MiddlewareFunction>,
19-
// Built-in support for devtools. Defaults to true.
20-
devTools: boolean,
21-
// Same as current createStore.
22-
preloadedState : State,
21+
reducer: Object<string, ReducerFunction> | ReducerFunction,
22+
// An array of Redux middlewares. If not supplied, uses getDefaultMiddleware()
23+
middleware?: MiddlewareFunction[],
24+
// Enable support for the Redux DevTools Extension. Defaults to true.
25+
devTools?: boolean,
2326
// Same as current createStore.
24-
enhancer : ReduxStoreEnhancer,
27+
preloadedState?: State,
28+
// An optional array of Redux store enhancers
29+
enhancers?: ReduxStoreEnhancer[],
2530
})
2631
```
2732

28-
For details on how the `middleware` parameter works and the list of middleware that are added by default, see the
29-
[`getDefaultMiddleware` docs page](./getDefaultMiddleware.md)
33+
### `reducer`
34+
35+
If this is a single function, it will be directly used as the root reducer for the store.
36+
37+
If it is an object of slice reducers, like `{users : usersReducer, posts : postsReducer}`,
38+
`configureStore` will automatically create the root reducer by passing this object to the
39+
[Redux `combineReducers` utility](https://redux.js.org/api/combinereducers).
40+
41+
42+
### `middleware`
43+
44+
An optional array of Redux middleware functions.
45+
46+
If this option is provided, it should contain all the middleware functions you
47+
want added to the store. `configureStore` will automatically pass those to `applyMiddleware`.
48+
49+
If not provided, `configureStore` will call `getDefaultMiddleware` and use the
50+
array of middleware functions it returns.
51+
52+
For more details on how the `middleware` parameter works and the list of middleware that are added by default, see the
53+
[`getDefaultMiddleware` docs page](./getDefaultMiddleware.md).
54+
55+
56+
### `devTools`
57+
58+
A boolean indicating whether `configureStore` should automatically enable support for [the Redux DevTools browser extension](https://github.com/zalmoxisus/redux-devtools-extension).
59+
60+
Defaults to true.
61+
62+
The Redux DevTools Extension recently added [support for showing action stack traces](https://github.com/zalmoxisus/redux-devtools-extension/blob/d4ef75691ad294646f74bca38b973b19850a37cf/docs/Features/Trace.md) that show exactly where each action was dispatched. Capturing the traces can add a bit of overhead, so the DevTools Extension allows users to configure whether action stack traces are captured.
63+
64+
If this parameter is true, then `configureStore` will enable capturing action stack traces in development mode only.
65+
66+
67+
### `preloadedState`
68+
69+
An optional initial state value to be passed to the Redux `createStore` function.
70+
71+
### `enhancers`
72+
73+
An optional array of Redux store enhancers. If included, these will be passed to [the Redux `compose` function](https://redux.js.org/api/compose), and the combined enhancer will be passed to `createStore`.
74+
75+
This should _not_ include `applyMiddleware()` or
76+
the Redux DevTools Extension `composeWithDevTools`, as those are already handled by `configureStore`.
77+
78+
79+
## Usage
3080

31-
Basic usage:
81+
### Basic Example
3282

3383
```js
3484
import { configureStore } from 'redux-starter-kit'
@@ -39,7 +89,7 @@ const store = configureStore({ reducer: rootReducer })
3989
// The store now has redux-thunk added and the Redux DevTools Extension is turned on
4090
```
4191

42-
Full example:
92+
### Full Example
4393

4494
```js
4595
import { configureStore, getDefaultMiddleware } from 'redux-starter-kit'
@@ -77,7 +127,7 @@ const preloadedState = {
77127
const store = configureStore({
78128
reducer,
79129
middleware,
80-
devTools: NODE_ENV !== 'production',
130+
devTools: process.env.NODE_ENV !== 'production',
81131
preloadedState,
82132
enhancers: [reduxBatch]
83133
})

docs/api/createAction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { increment } from './actions'
2727

2828
function counterReducer(state = 0, action) {
2929
switch (action.type) {
30-
// action creator can be used directly as the type for comparisons
31-
case increment: {
30+
// action creator's `toString()` can be used as the type for comparisons
31+
case increment.toString(): {
3232
return state + action.payload
3333
}
3434
default:

docs/api/otherExports.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,67 @@ hide_title: true
77

88
# Other Exports
99

10-
`redux-starter-kit` re-exports additional functions from other dependencies as well.
10+
`redux-starter-kit` exports some of its internal utilities, and re-exports additional functions from other dependencies as well.
1111

12-
## `createNextState`
12+
13+
## Internal Exports
14+
15+
16+
### `createSerializableStateInvariantMiddleware`
17+
18+
Creates an instance of the `serializable-state-invariant` middleware described in [`getDefaultMiddleware`](./getDefaultMiddleware.md).
19+
20+
Accepts an options object with an `isSerializable` parameter, which will be used
21+
to determine if a value is considered serializable or not. If not provided, this
22+
defaults to `isPlain`.
23+
24+
Example:
25+
26+
```js
27+
import {configureStore, createSerializableStateInvariantMiddleware} from "redux-starter-kit";
28+
29+
const serializableMiddleware = createSerializableStateInvariantMiddleware({
30+
isSerializable: () => true // all values will be accepted
31+
});
32+
33+
const store = configureStore({
34+
reducer,
35+
middleware : [serializableMiddleware],
36+
});
37+
```
38+
39+
### `isPlain`
40+
41+
The default function used to determine if a value is considered serializable.
42+
43+
Current definition:
44+
45+
```js
46+
function isPlain(val) {
47+
return (
48+
typeof val === 'undefined' ||
49+
val === null ||
50+
typeof val === 'string' ||
51+
typeof val === 'boolean' ||
52+
typeof val === 'number' ||
53+
Array.isArray(val) ||
54+
isPlainObject(val)
55+
)
56+
}
57+
```
58+
59+
60+
## Exports from Other Libraries
61+
62+
### `createNextState`
1363

1464
The default immutable update function from the [`immer` library](https://github.com/mweststrate/immer#api), re-exported here as `createNextState` (also commonly referred to as `produce`)
1565

16-
## `combineReducers`
66+
### `combineReducers`
1767

1868
Redux's `combineReducers`, re-exported for convenience. While `configureStore` calls this internally, you may wish to call it yourself to compose multiple levels of slice reducers.
1969

20-
## `compose`
70+
### `compose`
2171

2272
Redux's `compose`. It composes functions from right to left.
2373
This is a functional programming utility. You might want to use it to apply several store custom enhancers/ functions in a row.

docs/introduction/quick-start.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ you make your Redux code better.
2727

2828
`redux-starter-kit` includes:
2929

30-
- A `configureStore()` function with simplified configuration options. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includes `redux-thunk` by default, and enables use of the Redux DevTools Extension.
31-
- A `createReducer()` utility that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses the [`immer` library](https://github.com/mweststrate/immer) to let you write simpler immutable updates with normal mutative code, like `state.todos[3].completed = true`.
32-
- A `createAction()` utility that returns an action creator function for the given action type string. The function itself has `toString()` defined, so that it can be used in place of the type constant.
33-
- A `createSlice()` function that accepts a set of reducer functions, a slice name, and an initial state value, and automatically generates corresponding action creators, types, and simple selector functions.
34-
- An improved version of the widely used `createSelector` utility for creating memoized selector functions, which can accept string keypaths as "input selectors" (re-exported from the [`selectorator` library](https://github.com/planttheidea/selectorator)).
30+
- A [`configureStore()` function](./configureStore.md) with simplified configuration options. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includes `redux-thunk` by default, and enables use of the Redux DevTools Extension.
31+
- A [`createReducer()` utility](./createReducer.md) that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses the [`immer` library](https://github.com/mweststrate/immer) to let you write simpler immutable updates with normal mutative code, like `state.todos[3].completed = true`.
32+
- A [`createAction()` utility](./createAction.md) that returns an action creator function for the given action type string. The function itself has `toString()` defined, so that it can be used in place of the type constant.
33+
- A [`createSlice()` function](./createSlice.md) that accepts a set of reducer functions, a slice name, and an initial state value, and automatically generates corresponding action creators, types, and simple selector functions.
34+
- An improved version of the widely used [`createSelector` utility](./createSelector.md) for creating memoized selector functions, which can accept string keypaths as "input selectors" (re-exported from the [`selectorator` library](https://github.com/planttheidea/selectorator)).
3535

3636
## Installation
3737

0 commit comments

Comments
 (0)