You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,8 +86,61 @@ The easiest way to apply several store enhancers in a row is to use the [`compos
86
86
87
87
It’s important that you should add `DevTools.instrument()`*after*`applyMiddleware` in your `compose()` function arguments. This is because `applyMiddleware` is potentially asynchronous, but `DevTools.instrument()` expects all actions to be plain objects rather than actions interpreted by asynchronous middleware such as [redux-promise](https://github.com/acdlite/redux-promise) or [redux-thunk](https://github.com/gaearon/redux-thunk). So make sure `applyMiddleware()` goes first in the `compose()` call, and `DevTools.instrument()` goes after it.
// Hot reload reducers (requires Webpack or Browserify HMR to be enabled)
107
+
if (module.hot) {
108
+
module.hot.accept('../reducers', () =>
109
+
store.replaceReducer(require('../reducers')/*.default if you use Babel 6+ */)
110
+
);
111
+
}
112
+
113
+
return store;
114
+
}
115
+
```
116
+
89
117
If you’d like, you may add another store enhancer called `persistState()`. It ships with this package, and it lets you serialize whole sessions (including all dispatched actions and the state of the monitors) by a URL key. So if you visit `http://localhost:3000/?debug_session=reproducing_weird_bug`, do something in the app, then open `http://localhost:3000/?debug_session=some_other_feature`, and then go back to `http://localhost:3000/?debug_session=reproducing_weird_bug`, the state will be restored. The implementation of `persistState()` is fairly naïve but you can take it as an inspiration and build a proper UI for it if you feel like it!
90
118
119
+
```js
120
+
// ...
121
+
import { persistState } from'redux-devtools';
122
+
123
+
constfinalCreateStore=compose(
124
+
// Middleware you want to use in development:
125
+
applyMiddleware(d1, d2, d3),
126
+
// Required! Enable Redux DevTools with the monitors you chose
127
+
DevTools.instrument(),
128
+
// Optional. Lets you write ?debug_session=<key> in address bar to persist debug sessions
129
+
persistState(getDebugSessionKey())
130
+
)(createStore);
131
+
132
+
functiongetDebugSessionKey() {
133
+
// You can write custom logic here!
134
+
// By default we try to read the key from ?debug_session=<key> in the address bar
Finally, to make sure we’re not pulling any DevTools-related code in the production builds, we will envify our code. With Webpack, you can use `DefinePlugin` (Browserify equivalent is called [`envify`](https://github.com/zertosh/loose-envify)) to turn magic constants like `process.env.NODE_ENV` into `'production'` or `'development'` strings depending on the environment, and import and render `redux-devtools` conditionally when `process.env.NODE_ENV` is not `'production'`. Then, if you have an Uglify step before production, Uglify will eliminate dead `if (false)` branches with `redux-devtools` imports.
0 commit comments