|
27 | 27 |
|
28 | 28 | If you have a basic [store](http://redux.js.org/docs/api/createStore.html) as described in the official [redux-docs](http://redux.js.org/index.html), simply replace: |
29 | 29 | ```javascript |
30 | | - let store = createStore(reducer); |
| 30 | + const store = createStore(reducer); |
31 | 31 | ``` |
32 | 32 | with |
33 | 33 | ```javascript |
34 | | - let store = createStore(reducer, window.devToolsExtension && window.devToolsExtension()); |
| 34 | + const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); |
35 | 35 | ``` |
36 | 36 |
|
37 | | - Or with [initialState](http://redux.js.org/docs/api/createStore.html) but without middleware and enhancers arguments: |
| 37 | + Or with [preloadedState](http://redux.js.org/docs/api/createStore.html) but without middleware and enhancers arguments: |
38 | 38 |
|
39 | 39 | ```javascript |
40 | | - let store = createStore(reducer, initialState, |
41 | | - window.devToolsExtension && window.devToolsExtension() |
| 40 | + const store = createStore(reducer, preloadedState, |
| 41 | + window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() |
42 | 42 | ); |
43 | 43 | ``` |
44 | 44 |
|
|
51 | 51 | ```javascript |
52 | 52 | import { createStore, applyMiddleware, compose } from 'redux'; |
53 | 53 |
|
54 | | - let store = createStore(reducer, initialState, compose( |
| 54 | + const store = createStore(reducer, preloadedState, compose( |
55 | 55 | applyMiddleware(...middleware) |
56 | 56 | )); |
57 | 57 | ``` |
58 | | - to this: |
| 58 | + to: |
59 | 59 | ```javascript |
60 | | - let store = createStore(reducer, initialState, compose( |
61 | | - applyMiddleware(...middleware), |
62 | | - window.devToolsExtension ? window.devToolsExtension() : f => f |
| 60 | + import { createStore, applyMiddleware, compose } from 'redux'; |
| 61 | + |
| 62 | + const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; |
| 63 | + const store = createStore(reducer, preloadedState, composeEnhancers( |
| 64 | + applyMiddleware(...middleware) |
63 | 65 | )); |
64 | 66 | ``` |
65 | | - |
66 | | -#### 1.3 Together with Redux DevTools |
67 | | - You can use this extension together with vanilla [Redux DevTools](https://github.com/gaearon/redux-devtools) as a fallback, but not both simultaneously: |
| 67 | + When the extension is not installed, we’re using Redux compose here. |
| 68 | + |
| 69 | + In case you don’t want to allow the extension in production, [envify the code](https://github.com/gaearon/redux-devtools/blob/master/docs/Walkthrough.md#exclude-devtools-from-production-builds) and add `process.env.NODE_ENV !== 'production' && ` before `window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__`. |
| 70 | + |
| 71 | + To specify [extension’s options](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#windowdevtoolsextensionconfig) use it like that: |
68 | 72 | ```js |
69 | | - window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument() |
| 73 | + const composeEnhancers = |
| 74 | + process.env.NODE_ENV !== 'production' && |
| 75 | + typeof window === 'object' && |
| 76 | + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? |
| 77 | + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ |
| 78 | + name: 'MyApp', actionsBlacklist: ['REDUX_STORAGE_SAVE'] |
| 79 | + }) : compose; |
| 80 | + |
| 81 | + const enhancer = composeEnhancers( |
| 82 | + applyMiddleware(...middleware), |
| 83 | + // other store enhancers if any |
| 84 | + ); |
| 85 | + const store = createStore(reducer, enhancer); |
70 | 86 | ``` |
71 | 87 |
|
72 | | - [Make sure not to render DevTools when using the extension](https://github.com/zalmoxisus/redux-devtools-extension/issues/57) or you'll probably want to render the monitor from vanilla DevTools as follows: |
| 88 | + [See the post for more details](https://medium.com/@zalmoxis/improve-your-development-workflow-with-redux-devtools-extension-f0379227ff83). |
| 89 | + |
| 90 | +#### 1.3 Use `redux-devtools-extension` package from npm |
| 91 | + |
| 92 | + To make things easier, there's a npm package to install: |
| 93 | + ``` |
| 94 | + npm install --save redux-devtools-extension |
| 95 | + ``` |
| 96 | + and to use like that: |
73 | 97 | ```js |
74 | | - { !window.devToolsExtension ? <DevTools /> : null } |
| 98 | + import { createStore, applyMiddleware } from 'redux'; |
| 99 | + import { composeWithDevTools } from 'redux-devtools-extension'; |
| 100 | + |
| 101 | + const store = createStore(reducer, composeWithDevTools( |
| 102 | + applyMiddleware(...middleware), |
| 103 | + // other store enhancers if any |
| 104 | + )); |
75 | 105 | ``` |
76 | | - |
77 | | -#### 1.4 Use with universal (isomorphic) apps |
78 | | -```javascript |
79 | | - typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f |
80 | | -``` |
| 106 | + or if needed to apply [extension’s options](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#windowdevtoolsextensionconfig): |
| 107 | + ```js |
| 108 | + import { createStore, applyMiddleware } from 'redux'; |
| 109 | + import { composeWithDevTools } from 'redux-devtools-extension'; |
| 110 | + |
| 111 | + const composeEnhancers = composeWithDevTools({ |
| 112 | + name: 'MyApp', actionsBlacklist: ['REDUX_STORAGE_SAVE'] |
| 113 | + }); |
| 114 | + const store = createStore(reducer, composeEnhancers( |
| 115 | + applyMiddleware(...middleware), |
| 116 | + // other store enhancers if any |
| 117 | + )); |
| 118 | + ``` |
| 119 | + There’re just [few lines of code](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/npm-package/index.js). If you don’t want to allow the extension in production, just use ‘redux-devtools-extension/developmentOnly’ instead of ‘redux-devtools-extension’. |
| 120 | + |
81 | 121 | #### 1.5 For React Native, hybrid, desktop and server side Redux apps |
82 | 122 | Include [`Remote Redux DevTools`](https://github.com/zalmoxisus/remote-redux-devtools)'s store enhancer, and from the extension's context menu choose 'Open Remote DevTools' or press Alt+Shift+arrow up for remote monitoring. |
83 | 123 |
|
84 | | -### 2. For advanced usage see [our documentation](http://zalmoxisus.github.io/redux-devtools-extension/). |
| 124 | +### 2. Without Redux |
| 125 | + See [the post](https://medium.com/@zalmoxis/redux-devtools-without-redux-or-how-to-have-a-predictable-state-with-any-architecture-61c5f5a7716f) for more details on how to use the extension with any architecture. |
| 126 | + |
| 127 | +## API Reference |
| 128 | + - [Parameters](docs/API/Arguments.md) |
| 129 | + - [Methods](docs/API/Methods.md) |
| 130 | + - [Create Redux store right in the extension](docs/API/Methods.md). |
85 | 131 |
|
86 | 132 | ## Demo |
87 | 133 | Open these urls to test the extension: |
88 | 134 |
|
89 | 135 | - [Counter](http://zalmoxisus.github.io/examples/counter/) |
90 | 136 | - [TodoMVC](http://zalmoxisus.github.io/examples/todomvc/) |
91 | | - - [Redux Form](http://erikras.github.io/redux-form/#/examples/simple) |
92 | 137 | - [Redux Router](http://zalmoxisus.github.io/examples/router/) |
| 138 | + - [Redux Form](http://erikras.github.io/redux-form/#/examples/simple) |
93 | 139 |
|
94 | 140 | Also you may run them from `./examples` folder. |
95 | 141 |
|
|
0 commit comments