Skip to content

Commit f179ba8

Browse files
committed
Merge pull request #473 from gaearon/tweak-example-conventions
Tweak example conventions
2 parents ed33ec1 + 4de6324 commit f179ba8

File tree

23 files changed

+66
-54
lines changed

23 files changed

+66
-54
lines changed

examples/counter/actions/CounterActions.js renamed to examples/counter/actions/counter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
1+
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
2+
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';
23

34
export function increment() {
45
return {
@@ -24,7 +25,7 @@ export function incrementIfOdd() {
2425
};
2526
}
2627

27-
export function incrementAsync(delay=1000) {
28+
export function incrementAsync(delay = 1000) {
2829
return dispatch => {
2930
setTimeout(() => {
3031
dispatch(increment());

examples/counter/components/Counter.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { Component, PropTypes } from 'react';
22

33
class Counter extends Component {
4-
54
render() {
65
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props;
76
return (

examples/counter/constants/ActionTypes.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/counter/containers/CounterApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { bindActionCreators } from 'redux';
22
import { connect } from 'react-redux';
33
import Counter from '../components/Counter';
4-
import * as CounterActions from '../actions/CounterActions';
4+
import * as CounterActions from '../actions/counter';
55

66
function mapStateToProps(state) {
77
return {

examples/counter/containers/App.js renamed to examples/counter/containers/Root.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { Component } from 'react';
22
import { Provider } from 'react-redux';
33
import CounterApp from './CounterApp';
4-
import createCounterStore from '../store/createCounterStore';
4+
import configureStore from '../store/configureStore';
55

6-
const store = createCounterStore();
6+
const store = configureStore();
77

8-
export default class App extends Component {
8+
export default class Root extends Component {
99
render() {
1010
return (
1111
<Provider store={store}>

examples/counter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import App from './containers/App';
2+
import Root from './containers/Root';
33

44
React.render(
5-
<App />,
5+
<Root />,
66
document.getElementById('root')
77
);

examples/counter/reducers/counter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
1+
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../actions/counter';
22

33
export default function counter(state = 0, action) {
44
switch (action.type) {

examples/counter/reducers/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
export { default as counter } from './counter';
1+
import { combineReducers } from 'redux';
2+
import counter from './counter';
3+
4+
const rootReducer = combineReducers({
5+
counter
6+
});
7+
8+
export default rootReducer;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createStore, applyMiddleware, combineReducers } from 'redux';
2+
import thunk from 'redux-thunk';
3+
import rootReducer from '../reducers';
4+
5+
const createStoreWithMiddleware = applyMiddleware(
6+
thunk
7+
)(createStore);
8+
9+
export default function configureStore(initialState) {
10+
return createStoreWithMiddleware(rootReducer, initialState);
11+
}

examples/counter/store/createCounterStore.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/counter/test/actions/CounterActions.spec.js renamed to examples/counter/test/actions/counter.spec.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import expect from 'expect';
2-
import * as actions from '../../actions/CounterActions';
3-
import * as types from '../../constants/ActionTypes';
2+
import * as actions from '../../actions/counter';
43

54
describe('actions', () => {
65

76
it('increment should create increment action', () => {
8-
expect(actions.increment()).toEqual({ type: types.INCREMENT_COUNTER });
7+
expect(actions.increment()).toEqual({ type: actions.INCREMENT_COUNTER });
98
});
109

1110
it('decrement should create decrement action', () => {
12-
expect(actions.decrement()).toEqual({ type: types.DECREMENT_COUNTER });
11+
expect(actions.decrement()).toEqual({ type: actions.DECREMENT_COUNTER });
1312
});
1413

1514
it('incrementIfOdd should create increment action', () => {
@@ -18,7 +17,7 @@ describe('actions', () => {
1817
let dispatch = expect.createSpy();
1918
let getState = () => ({ counter: 1 });
2019
fn(dispatch, getState);
21-
expect(dispatch).toHaveBeenCalledWith({ type: types.INCREMENT_COUNTER });
20+
expect(dispatch).toHaveBeenCalledWith({ type: actions.INCREMENT_COUNTER });
2221
});
2322

2423
it('incrementIfOdd shouldnt create increment action if counter is even', () => {
@@ -36,7 +35,7 @@ describe('actions', () => {
3635
let dispatch = expect.createSpy();
3736
fn(dispatch);
3837
setTimeout(() => {
39-
expect(dispatch).toHaveBeenCalledWith({ type: types.INCREMENT_COUNTER });
38+
expect(dispatch).toHaveBeenCalledWith({ type: actions.INCREMENT_COUNTER });
4039
done();
4140
}, 5);
4241
});

examples/counter/test/containers/CounterApp.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import jsdomReact from '../jsdomReact';
33
import React from 'react/addons';
44
import { Provider } from 'react-redux';
55
import CounterApp from '../../containers/CounterApp';
6-
import createCounterStore from '../../store/createCounterStore';
6+
import configureStore from '../../store/configureStore';
77

88
const { TestUtils } = React.addons;
99

1010
function setup(initialState) {
11-
const store = createCounterStore(initialState);
11+
const store = configureStore(initialState);
1212
const app = TestUtils.renderIntoDocument(
1313
<Provider store={store}>
1414
{() => <CounterApp />}

examples/counter/test/reducers/counter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import expect from 'expect';
22
import counter from '../../reducers/counter';
3-
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../../constants/ActionTypes';
3+
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../../actions/counter';
44

55
describe('reducers', () => {
66
describe('counter', () => {

examples/real-world/containers/Root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { Component } from 'react';
22
import { Provider } from 'react-redux';
33
import { Router, Route } from 'react-router';
4-
import createAsyncExampleStore from '../store/createAsyncExampleStore';
4+
import configureStore from '../store/configureStore';
55
import App from './App';
66
import UserPage from './UserPage';
77
import RepoPage from './RepoPage';
88

9-
const store = createAsyncExampleStore();
9+
const store = configureStore();
1010

1111
export default class Root extends Component {
1212
render() {

examples/real-world/store/createAsyncExampleStore.js renamed to examples/real-world/store/configureStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ const createStoreWithMiddleware = applyMiddleware(
1414
/**
1515
* Creates a preconfigured store for this example.
1616
*/
17-
export default function createAsyncExampleStore(initialState) {
17+
export default function configureStore(initialState) {
1818
return createStoreWithMiddleware(reducer, initialState);
1919
}

examples/todomvc/containers/App.js renamed to examples/todomvc/containers/Root.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import React, { Component } from 'react';
22
import TodoApp from './TodoApp';
33
import { createStore, combineReducers } from 'redux';
44
import { Provider } from 'react-redux';
5-
import * as reducers from '../reducers';
5+
import rootReducer from '../reducers';
66

7-
const reducer = combineReducers(reducers);
8-
const store = createStore(reducer);
7+
const store = createStore(rootReducer);
98

10-
export default class App extends Component {
9+
export default class Root extends Component {
1110
render() {
1211
return (
1312
<Provider store={store}>

examples/todomvc/containers/TodoApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { bindActionCreators } from 'redux';
33
import { connect } from 'react-redux';
44
import Header from '../components/Header';
55
import MainSection from '../components/MainSection';
6-
import * as TodoActions from '../actions/TodoActions';
6+
import * as TodoActions from '../actions/todos';
77

88
class TodoApp extends Component {
99
render() {

examples/todomvc/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'babel/polyfill';
22

33
import React from 'react';
4-
import App from './containers/App';
4+
import Root from './containers/Root';
55
import 'todomvc-app-css/index.css';
66

77
React.render(
8-
<App />,
8+
<Root />,
99
document.getElementById('root')
1010
);

examples/todomvc/reducers/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
export { default as todos } from './todos';
1+
import { combineReducers } from 'redux';
2+
import todos from './todos';
3+
4+
const rootReducer = combineReducers({
5+
todos
6+
});
7+
8+
export default rootReducer;

examples/todomvc/reducers/todos.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/ActionTypes';
2+
import { combineReducers } from 'redux';
23

34
const initialState = [{
45
text: 'Use Redux',

examples/todomvc/test/actions/TodoActions.spec.js renamed to examples/todomvc/test/actions/todos.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import expect from 'expect';
22
import * as types from '../../constants/ActionTypes';
3-
import * as actions from '../../actions/TodoActions';
3+
import * as actions from '../../actions/todos';
44

55
describe('todo actions', () => {
66

examples/todomvc/test/reducers/todos.spec.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import expect from 'expect';
2-
import reducer from '../../reducers/todos';
2+
import todos from '../../reducers/todos';
33
import * as types from '../../constants/ActionTypes';
44

55
describe('todos reducer', () => {
66

77
it('should handle initial state', () => {
88
expect(
9-
reducer(undefined, {})
9+
todos(undefined, {})
1010
).toEqual([{
1111
text: 'Use Redux',
1212
completed: false,
@@ -16,7 +16,7 @@ describe('todos reducer', () => {
1616

1717
it('should handle ADD_TODO', () => {
1818
expect(
19-
reducer([], {
19+
todos([], {
2020
type: types.ADD_TODO,
2121
text: 'Run the tests'
2222
})
@@ -28,7 +28,7 @@ describe('todos reducer', () => {
2828
}]);
2929

3030
expect(
31-
reducer([{
31+
todos([{
3232
text: 'Use Redux',
3333
completed: false,
3434
id: 0
@@ -49,7 +49,7 @@ describe('todos reducer', () => {
4949

5050
it('should handle DELETE_TODO', () => {
5151
expect(
52-
reducer([{
52+
todos([{
5353
text: 'Run the tests',
5454
completed: false,
5555
id: 1
@@ -70,7 +70,7 @@ describe('todos reducer', () => {
7070

7171
it('should handle EDIT_TODO', () => {
7272
expect(
73-
reducer([{
73+
todos([{
7474
text: 'Run the tests',
7575
completed: false,
7676
id: 1
@@ -96,7 +96,7 @@ describe('todos reducer', () => {
9696

9797
it('should handle COMPLETE_TODO', () => {
9898
expect(
99-
reducer([{
99+
todos([{
100100
text: 'Run the tests',
101101
completed: false,
102102
id: 1
@@ -121,7 +121,7 @@ describe('todos reducer', () => {
121121

122122
it('should handle COMPLETE_ALL', () => {
123123
expect(
124-
reducer([{
124+
todos([{
125125
text: 'Run the tests',
126126
completed: true,
127127
id: 1
@@ -144,7 +144,7 @@ describe('todos reducer', () => {
144144

145145
// Unmark if all todos are currently completed
146146
expect(
147-
reducer([{
147+
todos([{
148148
text: 'Run the tests',
149149
completed: true,
150150
id: 1
@@ -168,7 +168,7 @@ describe('todos reducer', () => {
168168

169169
it('should handle CLEAR_COMPLETED', () => {
170170
expect(
171-
reducer([{
171+
todos([{
172172
text: 'Run the tests',
173173
completed: true,
174174
id: 1

0 commit comments

Comments
 (0)