Skip to content

Commit

Permalink
Fix lint errors in examples/counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ellbee committed Oct 27, 2015
1 parent e9e4c56 commit deafee9
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 211 deletions.
26 changes: 13 additions & 13 deletions examples/buildAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
* Runs an ordered set of commands within each of the build directories.
*/

import fs from 'fs';
import path from 'path';
import { spawnSync } from 'child_process';
import fs from 'fs'
import path from 'path'
import { spawnSync } from 'child_process'

var exampleDirs = fs.readdirSync(__dirname).filter((file) => {
return fs.statSync(path.join(__dirname, file)).isDirectory();
});
return fs.statSync(path.join(__dirname, file)).isDirectory()
})

// Ordering is important here. `npm install` must come first.
var cmdArgs = [
{ cmd: 'npm', args: ['install'] },
{ cmd: 'webpack', args: ['index.js'] }
];
{ cmd: 'npm', args: [ 'install' ] },
{ cmd: 'webpack', args: [ 'index.js' ] }
]

for (const dir of exampleDirs) {
for (const cmdArg of cmdArgs) {
// declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
const opts = {
cwd: path.join(__dirname, dir),
stdio: 'inherit'
};
let result = {};
}
let result = {}
if (process.platform === 'win32') {
result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts);
result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts)
} else {
result = spawnSync(cmdArg.cmd, cmdArg.args, opts);
result = spawnSync(cmdArg.cmd, cmdArg.args, opts)
}
if (result.status !== 0) {
throw new Error('Building examples exited with non-zero');
throw new Error('Building examples exited with non-zero')
}
}
}
22 changes: 11 additions & 11 deletions examples/counter/actions/counter.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'

export function increment() {
return {
type: INCREMENT_COUNTER
};
}
}

export function decrement() {
return {
type: DECREMENT_COUNTER
};
}
}

export function incrementIfOdd() {
return (dispatch, getState) => {
const { counter } = getState();
const { counter } = getState()

if (counter % 2 === 0) {
return;
return
}

dispatch(increment());
};
dispatch(increment())
}
}

export function incrementAsync(delay = 1000) {
return dispatch => {
setTimeout(() => {
dispatch(increment());
}, delay);
};
dispatch(increment())
}, delay)
}
}
10 changes: 5 additions & 5 deletions examples/counter/components/Counter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component, PropTypes } from 'react';
import React, { Component, PropTypes } from 'react'

class Counter extends Component {
render() {
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props;
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props
return (
<p>
Clicked: {counter} times
Expand All @@ -15,7 +15,7 @@ class Counter extends Component {
{' '}
<button onClick={() => incrementAsync()}>Increment async</button>
</p>
);
)
}
}

Expand All @@ -25,6 +25,6 @@ Counter.propTypes = {
incrementAsync: PropTypes.func.isRequired,
decrement: PropTypes.func.isRequired,
counter: PropTypes.number.isRequired
};
}

export default Counter;
export default Counter
14 changes: 7 additions & 7 deletions examples/counter/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Counter from '../components/Counter';
import * as CounterActions from '../actions/counter';
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import Counter from '../components/Counter'
import * as CounterActions from '../actions/counter'

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

function mapDispatchToProps(dispatch) {
return bindActionCreators(CounterActions, dispatch);
return bindActionCreators(CounterActions, dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(Counter);
export default connect(mapStateToProps, mapDispatchToProps)(Counter)
14 changes: 7 additions & 7 deletions examples/counter/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import App from './containers/App';
import configureStore from './store/configureStore';
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import App from './containers/App'
import configureStore from './store/configureStore'

const store = configureStore();
const store = configureStore()

render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
)
14 changes: 7 additions & 7 deletions examples/counter/reducers/counter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../actions/counter';
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../actions/counter'

export default function counter(state = 0, action) {
switch (action.type) {
case INCREMENT_COUNTER:
return state + 1;
case DECREMENT_COUNTER:
return state - 1;
default:
return state;
case INCREMENT_COUNTER:
return state + 1
case DECREMENT_COUNTER:
return state - 1
default:
return state
}
}
8 changes: 4 additions & 4 deletions examples/counter/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { combineReducers } from 'redux';
import counter from './counter';
import { combineReducers } from 'redux'
import counter from './counter'

const rootReducer = combineReducers({
counter
});
})

export default rootReducer;
export default rootReducer
28 changes: 14 additions & 14 deletions examples/counter/server.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var config = require('./webpack.config');
var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config')

var app = new require('express')();
var port = 3000;
var app = new require('express')()
var port = 3000

var compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }));
app.use(webpackHotMiddleware(compiler));
var compiler = webpack(config)
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }))
app.use(webpackHotMiddleware(compiler))

app.get("/", function(req, res) {
res.sendFile(__dirname + '/index.html');
});
res.sendFile(__dirname + '/index.html')
})

app.listen(port, function(error) {
if (error) {
console.error(error);
console.error(error)
} else {
console.info("==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port);
console.info("==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port)
}
});
})
18 changes: 9 additions & 9 deletions examples/counter/store/configureStore.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from '../reducers';
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import reducer from '../reducers'

const createStoreWithMiddleware = applyMiddleware(
thunk
)(createStore);
)(createStore)

export default function configureStore(initialState) {
const store = createStoreWithMiddleware(reducer, initialState);
const store = createStoreWithMiddleware(reducer, initialState)

if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers');
store.replaceReducer(nextReducer);
});
const nextReducer = require('../reducers')
store.replaceReducer(nextReducer)
})
}

return store;
return store
}
66 changes: 33 additions & 33 deletions examples/counter/test/actions/counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import expect from 'expect';
import { applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import * as actions from '../../actions/counter';
import expect from 'expect'
import { applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import * as actions from '../../actions/counter'

const middlewares = [thunk];
const middlewares = [ thunk ]

/*
* Creates a mock of Redux store with middleware.
*/
function mockStore(getState, expectedActions, onLastAction) {
if (!Array.isArray(expectedActions)) {
throw new Error('expectedActions should be an array of expected actions.');
throw new Error('expectedActions should be an array of expected actions.')
}
if (typeof onLastAction !== 'undefined' && typeof onLastAction !== 'function') {
throw new Error('onLastAction should either be undefined or function.');
throw new Error('onLastAction should either be undefined or function.')
}

function mockStoreWithoutMiddleware() {
return {
getState() {
return typeof getState === 'function' ?
getState() :
getState;
getState
},

dispatch(action) {
const expectedAction = expectedActions.shift();
expect(action).toEqual(expectedAction);
const expectedAction = expectedActions.shift()
expect(action).toEqual(expectedAction)
if (onLastAction && !expectedActions.length) {
onLastAction();
onLastAction()
}
return action;
return action
}
};
}
}

const mockStoreWithMiddleware = applyMiddleware(
...middlewares
)(mockStoreWithoutMiddleware);
)(mockStoreWithoutMiddleware)

return mockStoreWithMiddleware();
return mockStoreWithMiddleware()
}

describe('actions', () => {
it('increment should create increment action', () => {
expect(actions.increment()).toEqual({ type: actions.INCREMENT_COUNTER });
});
expect(actions.increment()).toEqual({ type: actions.INCREMENT_COUNTER })
})

it('decrement should create decrement action', () => {
expect(actions.decrement()).toEqual({ type: actions.DECREMENT_COUNTER });
});
expect(actions.decrement()).toEqual({ type: actions.DECREMENT_COUNTER })
})

it('incrementIfOdd should create increment action', (done) => {
const expectedActions = [
{ type: actions.INCREMENT_COUNTER }
];
const store = mockStore({ counter: 1 }, expectedActions, done);
store.dispatch(actions.incrementIfOdd());
});
]
const store = mockStore({ counter: 1 }, expectedActions, done)
store.dispatch(actions.incrementIfOdd())
})

it('incrementIfOdd shouldnt create increment action if counter is even', (done) => {
const expectedActions = [];
const store = mockStore({ counter: 2 }, expectedActions);
store.dispatch(actions.incrementIfOdd());
done();
});
const expectedActions = []
const store = mockStore({ counter: 2 }, expectedActions)
store.dispatch(actions.incrementIfOdd())
done()
})

it('incrementAsync should create increment action', (done) => {
const expectedActions = [
{ type: actions.INCREMENT_COUNTER }
];
const store = mockStore({ counter: 0 }, expectedActions, done);
store.dispatch(actions.incrementAsync(100));
});
});
]
const store = mockStore({ counter: 0 }, expectedActions, done)
store.dispatch(actions.incrementAsync(100))
})
})
Loading

0 comments on commit deafee9

Please sign in to comment.