Skip to content

update counter example to use react-redux v0.5.1 #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions examples/counter/components/Counter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as CounterActions from '../actions/CounterActions';

class Counter extends Component {
export class CounterComponent extends Component {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep calling it Counter?


render() {
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props;
const { actions: { increment, incrementIfOdd, incrementAsync, decrement }, counter } = this.props;
return (
<p>
Clicked: {counter} times
Expand All @@ -20,12 +23,26 @@ class Counter extends Component {
}
}

Counter.propTypes = {
increment: PropTypes.func.isRequired,
incrementIfOdd: PropTypes.func.isRequired,
incrementAsync: PropTypes.func.isRequired,
decrement: PropTypes.func.isRequired,
CounterComponent.propTypes = {
actions: PropTypes.shape({
increment: PropTypes.func.isRequired,
incrementIfOdd: PropTypes.func.isRequired,
incrementAsync: PropTypes.func.isRequired,
decrement: PropTypes.func.isRequired
}),
counter: PropTypes.number.isRequired
};

export default Counter;
function mapStateToProps(state) {
return {
counter: state.counter
}
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(CounterActions, dispatch)
}
}

export default connect(mapStateToProps, mapDispatchToProps)(CounterComponent);
4 changes: 2 additions & 2 deletions examples/counter/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import CounterApp from './CounterApp';
import Counter from '../components/Counter';
import createCounterStore from '../store/createCounterStore';

const store = createCounterStore();
Expand All @@ -9,7 +9,7 @@ export default class App extends Component {
render() {
return (
<Provider store={store}>
{() => <CounterApp />}
{() => <Counter />}
</Provider>
);
}
Expand Down
23 changes: 0 additions & 23 deletions examples/counter/containers/CounterApp.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"homepage": "https://github.com/gaearon/redux#readme",
"dependencies": {
"react": "^0.13.3",
"react-redux": "^0.4.0",
"react-redux": "^0.5.1",
"redux": "^1.0.0-rc",
"redux-thunk": "^0.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/counter/test/components/Counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import expect from 'expect';
import jsdomReact from '../jsdomReact';
import React from 'react/addons';
import Counter from '../../components/Counter';
import { CounterComponent as Counter } from '../../components/Counter';

const { TestUtils } = React.addons;

Expand All @@ -12,7 +12,7 @@ function setup() {
incrementAsync: expect.createSpy(),
decrement: expect.createSpy()
};
const component = TestUtils.renderIntoDocument(<Counter counter={1} {...actions} />);
const component = TestUtils.renderIntoDocument(<Counter counter={1} actions={actions} />);
return {
component: component,
actions: actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect';
import jsdomReact from '../jsdomReact';
import React from 'react/addons';
import { Provider } from 'react-redux';
import CounterApp from '../../containers/CounterApp';
import Counter from '../../components/Counter';
import createCounterStore from '../../store/createCounterStore';

const { TestUtils } = React.addons;
Expand All @@ -11,7 +11,7 @@ function setup(initialState) {
const store = createCounterStore(initialState);
const app = TestUtils.renderIntoDocument(
<Provider store={store}>
{() => <CounterApp />}
{() => <Counter />}
</Provider>
);
return {
Expand Down