|
| 1 | +# API Reference |
| 2 | + |
| 3 | +`window.devToolsExtension` function can be used in 2 ways: |
| 4 | + 1. [Apply as Redux store enhancer](#windowdevtoolsextensionconfig) |
| 5 | + 2. [Create Redux store right in the extension](#windowdevtoolsextensionreducer-initialstate-config). |
| 6 | + |
| 7 | + |
| 8 | +### `window.devToolsExtension([config])` |
| 9 | +- [`config`] *(object)*: options |
| 10 | + - **name** (*string*) - the instance name to be showed on the monitor page. Default value is `document.title`. |
| 11 | + - **deserializeState(state): transformedState** (*function*) - optional transformation of state deserialized from debug session (useful if state is not plain object. Example: immutable-js state) |
| 12 | + - state, transformedState - Redux state objects. |
| 13 | + Example of usage: |
| 14 | + |
| 15 | + ```js |
| 16 | + const store = createStore(rootReducer, window.devToolsExtension && window.devToolsExtension({ |
| 17 | + deserializeState: (state) => ({ |
| 18 | + todos: { |
| 19 | + ...state.todos, |
| 20 | + todoList: Immutable.fromJS(state.todos.todoList) |
| 21 | + } |
| 22 | + }) |
| 23 | + })); |
| 24 | + ``` |
| 25 | + - **deserializeAction(action): transformedAction** (*function*) - optional transformation of actions deserialized from debug session (useful if actions are not plain object. Example: immutable-js action payload) |
| 26 | + - action, transformedAction - Redux action objects |
| 27 | + - **actionsBlacklist** (*array*) - actions to be hidden in DevTools. Overwrites corresponding global setting in the options page. |
| 28 | + - **actionsWhitelist** (*array*) - all other actions will be hidden in DevTools. Overwrites corresponding global setting in the options page. |
| 29 | + - **actionsFilter** (*function*) - function which takes `action` object and id number as arguments, and should return `action` object back. See the example bellow. |
| 30 | + - **statesFilter** (*function*) - function which takes `state` object and index as arguments, and should return `state` object back. |
| 31 | + Example of usage: |
| 32 | + |
| 33 | + ```js |
| 34 | + const actionsFilter = (action) => ( |
| 35 | + action.type === 'FILE_DOWNLOAD_SUCCESS' && action.data ? |
| 36 | + { ...action, data: '<<LONG_BLOB>>' } : action |
| 37 | + ); |
| 38 | + const store = createStore(rootReducer, window.devToolsExtension && window.devToolsExtension({ |
| 39 | + actionsFilter, |
| 40 | + statesFilter: (state) => state.data ? { ...state, data: '<<LONG_BLOB>>' } : state) |
| 41 | + })); |
| 42 | + ``` |
| 43 | + |
| 44 | +### `window.devToolsExtension(reducer, [preloadedState, config])` |
| 45 | +> Note: This is not intended to replace Redux' `createStore`. Use this approach only when you want to inspect changes outside of Redux or when not using Redux inside your application. |
| 46 | +
|
| 47 | +1. `reducer` *(Function)*: A [reducing function](https://github.com/reactjs/redux/blob/master/docs/Glossary.md#reducer) that returns the next [state tree](../Glossary.md#state), given the current state tree and an [action](https://github.com/reactjs/redux/blob/master/docs/Glossary.md#action) to handle. |
| 48 | +
|
| 49 | +2. [`preloadedState`] *(any)*: The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced `reducer` with [`combineReducers`](combineReducers.md), this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your `reducer` can understand. |
| 50 | +
|
| 51 | +3. [`config`] *(Object)*: options. See [above](#windowdevtoolsextensionconfig) for details. |
| 52 | +
|
| 53 | +[Example of usage](https://github.com/zalmoxisus/redux-devtools-extension/commit/1810d2c1f0e8be1daf8f2d8f7bbeb4f8c528d90b). |
0 commit comments