Skip to content

Commit 2521c52

Browse files
committed
Update readme for v3 release
1 parent 1752ccc commit 2521c52

File tree

1 file changed

+120
-35
lines changed

1 file changed

+120
-35
lines changed

README.md

Lines changed: 120 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ A live-editing time travel environment for [Redux](https://github.com/rackt/redu
77
[![build status](https://img.shields.io/travis/gaearon/redux-devtools/master.svg?style=flat-square)](https://travis-ci.org/gaearon/redux-devtools)
88
[![npm version](https://img.shields.io/npm/v/redux-devtools.svg?style=flat-square)](https://www.npmjs.com/package/redux-devtools)
99
[![npm downloads](https://img.shields.io/npm/dm/redux-devtools.svg?style=flat-square)](https://www.npmjs.com/package/redux-devtools)
10-
[![redux channel on slack](https://img.shields.io/badge/[email protected]?style=flat-square)](http://www.reactiflux.com)
11-
10+
[![redux channel on discord](https://img.shields.io/badge/[email protected]?style=flat-square)](https://discord.gg/0ZcbPKXt5bWb10Ma)
1211

1312
![](http://i.imgur.com/J4GeW0M.gif)
1413

1514
### Features
1615

1716
* Lets you inspect every state and action payload
1817
* Lets you go back in time by “cancelling” actions
19-
* If you change the reducer code, each “staged” action will be re-evaluted
18+
* If you change the reducer code, each “staged” action will be re-evaluated
2019
* If the reducers throw, you will see during which action this happened, and what the error was
2120
* With `persistState()` store enhancer, you can persist debug sessions across page reloads
22-
* Toggle visibility with Ctrl+H
2321

2422
### Installation
2523

@@ -29,57 +27,152 @@ npm install --save-dev redux-devtools
2927

3028
DevTools is a [store enhancer](http://rackt.github.io/redux/docs/Glossary.html#store-enhancer), which should be added to your middleware stack *after* [`applyMiddleware`](http://rackt.github.io/redux/docs/api/applyMiddleware.html) as `applyMiddleware` is potentially asynchronous. Otherwise, DevTools won’t see the raw actions emitted by asynchronous middleware such as [redux-promise](https://github.com/acdlite/redux-promise) or [redux-thunk](https://github.com/gaearon/redux-thunk).
3129

32-
To install, firstly import `devTools` into your root React component:
30+
To use, first create a `DevTools` component by passing a `monitor` component to `createDevTools`. In the following example our `monitor` consists of [`redux-devtools-log-monitor`](https://github.com/gaearon/redux-devtools-log-monitor) docked within [`redux-devtools-dock-monitor`](https://github.com/gaearon/redux-devtools-dock-monitor):
31+
32+
####containers/DevTools.js
3333

3434
```js
35-
// Redux utility functions
36-
import { compose, createStore, applyMiddleware } from 'redux';
35+
import React from 'react';
3736

38-
// Redux DevTools store enhancers
39-
import { devTools, persistState } from 'redux-devtools';
37+
// createDevTools takes a monitor and produces a DevTools component
38+
import { createDevTools } from 'redux-devtools';
4039

41-
// A monitor component for Redux DevTools
40+
// Monitor component for Redux DevTools
4241
import LogMonitor from 'redux-devtools-log-monitor';
42+
43+
// Dock component to contain a Redux DevTools monitor
44+
import DockMonitor from 'redux-devtools-dock-monitor';
45+
46+
export default createDevTools(
47+
<DockMonitor toggleVisibilityKey='H'
48+
changePositionKey='Q'>
49+
<LogMonitor />
50+
</DockMonitor>
51+
);
4352
```
4453

45-
Then, add `devTools` to your store enhancers, and create your store:
54+
Note that it is not essential to put [`redux-devtools-log-monitor`](https://github.com/gaearon/redux-devtools-log-monitor) inside the dock component, it can be placed wherever you like in the component tree.
55+
56+
Next add `instrument()` and (optionally) `persistState()` to your store enhancers, and create your store:
4657

4758
```js
59+
60+
import { createStore, compose } from 'redux';
61+
import { persistState } from 'redux-devtools';
62+
import rootReducer from '../reducers';
63+
import DevTools from '../containers/DevTools';
64+
4865
const finalCreateStore = compose(
4966
// Enables your middleware:
5067
applyMiddleware(m1, m2, m3), // any Redux middleware, e.g. redux-thunk
5168

52-
// Provides support for DevTools:
53-
devTools(),
69+
// Provide support for DevTools
70+
DevTools.instrument(),
5471

5572
// Lets you write ?debug_session=<name> in address bar to persist debug sessions
56-
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
73+
persistState(
74+
window.location.href.match(
75+
/[?&]debug_session=([^&]+)\b/
76+
)
77+
)
5778
)(createStore);
5879

59-
const store = finalCreateStore(reducer);
80+
export default function configureStore(initialState) {
81+
const store = finalCreateStore(rootReducer, initialState);
82+
83+
// enable hot reloading for the store
84+
if (module.hot) {
85+
module.hot.accept('../reducers', () =>
86+
store.replaceReducer(require('../reducers'))
87+
);
88+
}
89+
90+
return store;
91+
}
92+
```
93+
94+
Finally, include the DevTools component in your page:
95+
96+
####index.js
97+
98+
```js
99+
import React from 'react';
100+
import { render } from 'react-dom';
101+
import { Provider } from 'react-redux';
102+
import configureStore from './store/configureStore';
103+
import TodoApp from './TodoApp';
104+
import DevTools from './DevTools';
105+
106+
const store = configureStore();
107+
108+
render(
109+
<Provider store={store}>
110+
<div>
111+
<TodoApp />
112+
<DevTools />
113+
</div>
114+
</Provider>
115+
document.getElementById('app')
116+
);
117+
```
118+
119+
**Make sure to only use DevTools in development!** In production it will be terribly slow because currently actions just accumulate forever.
120+
121+
In Webpack, you can use `DefinePlugin` to turn magic constants like `__DEV__` into `true` or `false` depending on the environment, and import and render `redux-devtools` conditionally behind `if (__DEV__)`. Then, if you have an Uglify step before production, Uglify will eliminate dead `if (false)` branches with `redux-devtools` imports.
122+
123+
If you are using ES6 modules with Webpack 1.x, you might try putting your `import` statement inside an `if (__DEV__)` to exclude the DevTools package from your production bundle. This will not work. However, you can work around this by creating separate `dev` and `prod` Root components that are dynamically imported using commonJS `require`:
124+
125+
####containers/Root.js
126+
127+
```js
128+
if (process.env.NODE_ENV === 'production') {
129+
module.exports = require('./Root.prod');
130+
} else {
131+
module.exports = require('./Root.dev');
132+
}
60133
```
61134

62-
Finally, include the `DevTools` in your page. You may pass either `LogMonitor` (the default one) or any of the custom monitors described below.
135+
####Root.dev.js
63136

64137
```js
138+
import React, { Component } from 'react';
139+
import { Provider } from 'react-redux';
140+
import TodoApp from './TodoApp';
141+
import DevTools from './DevTools';
142+
65143
export default class Root extends Component {
66144
render() {
145+
const { store } = this.props;
67146
return (
68-
<div>
69-
<Provider store={store}>
70-
<CounterApp />
71-
</Provider>
72-
73-
<LogMonitor store={store.devToolsStore} />
74-
</div>
147+
<Provider store={store}>
148+
<div>
149+
<TodoApp />
150+
<DevTools />
151+
</div>
152+
</Provider>
75153
);
76154
}
77155
}
78156
```
79157

80-
**Make sure to only apply `devTools()` in development!** In production, this will be terribly slow because actions just accumulate forever. (We'll need to implement a rolling window for dev too.)
158+
####Root.prod.js
81159

82-
For example, in Webpack, you can use `DefinePlugin` to turn magic constants like `__DEV__` into `true` or `false` depending on the environment, and import and render `redux-devtools` conditionally behind `if (__DEV__)`. Then, if you have an Uglify step before production, Uglify will eliminate dead `if (false)` branches with `redux-devtools` imports. Here is [an example](https://github.com/erikras/react-redux-universal-hot-example/) that adds Redux DevTools handling the production case correctly.
160+
```js
161+
import React, { Component } from 'react';
162+
import { Provider } from 'react-redux';
163+
import TodoApp from './TodoApp';
164+
165+
export default class Root extends Component {
166+
render() {
167+
const { store } = this.props;
168+
return (
169+
<Provider store={store}>
170+
<TodoApp />
171+
</Provider>
172+
);
173+
}
174+
}
175+
```
83176

84177
### Running Examples
85178

@@ -103,7 +196,7 @@ Oh, and you can do the same with the TodoMVC example as well.
103196

104197
### Custom Monitors
105198

106-
**You can build a completely custom UI for it** because `<DevTools>` accepts a `monitor` React component prop. The included `LogMonitor` is just an example.
199+
**DevTools accepts monitor components so you can build a completely custom UI.** [`redux-devtools-log-monitor`](https://github.com/gaearon/redux-devtools-log-monitor) and [`redux-devtools-dock-monitor`](https://github.com/gaearon/redux-devtools-dock-monitor) are just examples of what is possible.
107200

108201
**[I challenge you to build a custom monitor for Redux DevTools!](https://github.com/gaearon/redux-devtools/issues/3)**
109202

@@ -112,22 +205,14 @@ Some crazy ideas for custom monitors:
112205
* A slider that lets you jump between computed states just by dragging it
113206
* An in-app layer that shows the last N states right in the app (e.g. for animation)
114207
* A time machine like interface where the last N states of your app reside on different Z layers
115-
* Feel free to come up with and implement your own! Check `LogMonitor` propTypes to see what you can do.
208+
* Feel free to come up with and implement your own! Check [`redux-devtools-log-monitor`](https://github.com/gaearon/redux-devtools-log-monitor) propTypes to see what you can do.
116209

117210
In fact some of these are implemented already:
118211

119-
#### [redux-devtools-diff-monitor](https://github.com/whetstone/redux-devtools-diff-monitor)
120-
121-
![](http://i.imgur.com/rvCR9OQ.png)
122-
123212
#### [redux-slider-monitor](https://github.com/calesce/redux-slider-monitor)
124213

125214
![](https://camo.githubusercontent.com/d61984306d27d5e0739efc2d57c56ba7aed7996c/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f662e636c2e6c792f6974656d732f3269314c3147316e3161316833793161324f31772f53637265656e2532305265636f7264696e67253230323031352d30382d3034253230617425323030372e3435253230504d2e676966)
126215

127-
#### [redux-devtools-gentest-plugin](https://github.com/lapanoid/redux-devtools-gentest-plugin)
128-
129-
![](https://camo.githubusercontent.com/71452cc55bc2ac2016dc05e4b6207c5777028a67/687474703a2f2f646c312e6a6f78692e6e65742f64726976652f303031302f333937372f3639323130352f3135303731362f643235343637613236362e706e67)
130-
131216
#### Keep them coming!
132217

133218
Create a PR to add your custom monitor.

0 commit comments

Comments
 (0)