Permalink
Browse files

Add the extension to react-counter example

  • Loading branch information...
zalmoxisus committed May 25, 2016
1 parent ae818c9 commit 1810d2c1f0e8be1daf8f2d8f7bbeb4f8c528d90b
Showing with 14 additions and 1 deletion.
  1. +14 −1 examples/react-counter/components/Counter.js
@@ -1,5 +1,10 @@
import React, { Component, PropTypes } from 'react';
const withDevTools = (
// process.env.NODE_ENV === 'development' &&
typeof window !== 'undefined' && window.devToolsExtension
);
const reducer = (state = { counter: 0 }, action) => {
switch (action.type) {
case 'INCREMENT':
@@ -20,8 +25,16 @@ class Counter extends Component {
this.decrement = this.decrement.bind(this);
}
componentWillMount() {
if (withDevTools) {
this.store = window.devToolsExtension(reducer);
this.store.subscribe(() => { this.setState(this.store.getState()); });
}
}
dispatch(action) {
this.setState(reducer(this.state, action));
if (withDevTools) this.store.dispatch(action);
else this.setState(reducer(this.state, action));
}
increment() {

0 comments on commit 1810d2c

Please sign in to comment.