Skip to content

Commit 2b70502

Browse files
committed
Devtools in counter example
1 parent f252459 commit 2b70502

File tree

8 files changed

+57
-12
lines changed

8 files changed

+57
-12
lines changed

examples/counter/containers/App.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import { Inject } from 'angular2/di';
1818
[increment-If-Odd]="incrementIfOdd"
1919
[increment-Async]="incrementAsync">
2020
</counter>
21+
<dev
2122
`
2223
})
2324
export default class App {
2425

2526
protected unsubscribe: Function;
2627

27-
constructor( @Inject('ngRedux') ngRedux) {
28+
constructor( @Inject('ngRedux') ngRedux, @Inject('devTools') devTools) {
29+
devTools.start(ngRedux);
2830
this.unsubscribe = ngRedux.connect(this.mapState, this.mapDispatch)(this);
2931
}
3032

examples/counter/devTools.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react';
2+
import React, { Component } from 'react';
3+
import {bind} from 'angular2/di';
4+
5+
let devTools = bind('devTools').toFactory(() => {
6+
return {
7+
start: (ngRedux) => {
8+
startDevTools(ngRedux);
9+
}
10+
};
11+
});
12+
13+
export default devTools;
14+
15+
function startDevTools(ngRedux) {
16+
React.render(
17+
<DevToolsReactComponent store={ ngRedux }/>,
18+
document.getElementById('devTools')
19+
);
20+
}
21+
22+
class DevToolsReactComponent extends Component {
23+
render() {
24+
return (
25+
<div>
26+
<DebugPanel top right bottom>
27+
<DevTools store={ this.props.store } monitor = { LogMonitor } />
28+
</DebugPanel>
29+
</div>
30+
);
31+
}
32+
}
33+

examples/counter/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</head>
88
<body>
99
<root></root>
10+
<div id="devTools"></div>
1011
</body>
1112
<script src="/static/bundle.js"></script>
1213
</html>

examples/counter/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import {bind} from 'angular2/di';
33
import App from './containers/App';
44
import configureStore from './store/configureStore';
55
const provider = require('ng2-redux').provider;
6-
6+
const devTools = require('./devTools');
77
const store = configureStore();
88

99
bootstrap(
1010
App,
11-
[provider(store)]
12-
);
11+
[
12+
provider(store),
13+
devTools
14+
]
15+
);

examples/counter/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
"homepage": "https://github.com/gaearon/redux#readme",
2929
"dependencies": {
3030
"angular2": "2.0.0-alpha.30",
31-
"ng2-redux": "2.0.0-alpha.2",
31+
"ng2-redux": "2.0.0-alpha.3",
3232
"react": "^0.13.3",
33-
"redux": "^1.0.0-rc",
33+
"redux": "^3.0.0",
34+
"redux-devtools": "^2.1.0",
3435
"redux-thunk": "^0.1.0",
3536
"reflect-metadata": "^0.1.0",
3637
"rtts_assert": "2.0.0-alpha.30",
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import {createStore, applyMiddleware} from 'redux';
1+
import {createStore, applyMiddleware, compose} from 'redux';
22
const thunk = require('redux-thunk');
33
import reducer from '../reducers/index';
4+
const devTools = require('redux-devTools').devTools;
45

5-
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
6+
const finalCreateStore = compose(
7+
applyMiddleware(thunk),
8+
devTools()
9+
)(createStore);
610

711
export default () => {
8-
const store = createStoreWithMiddleware(reducer);
9-
10-
return store;
12+
return finalCreateStore(reducer);
1113
}

examples/counter/typings/redux/redux.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ declare module Redux {
4444
function bindActionCreators<T>(actionCreators: T, dispatch: Dispatch): T;
4545
function combineReducers(reducers: any): Reducer;
4646
function applyMiddleware(...middleware: Middleware[]): Function;
47+
function compose<T extends Function>(...functions: Function[]): T;
4748
}
4849

4950
declare module "redux" {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"mocha": "^2.2.5",
3030
"sinon": "^1.16.1",
3131
"webpack": "^1.10.5",
32-
"angular2": "^2.0.0-alpha.30"
32+
"angular2": "^2.0.0-alpha.30",
33+
"react": "^0.13.3",
34+
"redux-devtools": "^2.1.0"
3335
},
3436
"peerDependencies": {
3537
"redux": "^2.0.0 || ^3.0.0",

0 commit comments

Comments
 (0)