- )
+ );
}
}
@@ -73,26 +74,26 @@ App.propTypes = {
posts: PropTypes.array.isRequired,
isFetching: PropTypes.bool.isRequired,
lastUpdated: PropTypes.number,
- dispatch: PropTypes.func.isRequired
-}
+ dispatch: PropTypes.func.isRequired,
+};
function mapStateToProps(state) {
- const { selectedReddit, postsByReddit } = state
+ const { selectedReddit, postsByReddit } = state;
const {
isFetching,
lastUpdated,
- items: posts
+ items: posts,
} = postsByReddit[selectedReddit] || {
isFetching: true,
- items: []
- }
+ items: [],
+ };
return {
selectedReddit,
posts,
isFetching,
- lastUpdated
- }
+ lastUpdated,
+ };
}
-export default connect(mapStateToProps)(App)
+export default connect(mapStateToProps)(App);
diff --git a/examples/async/index.js b/examples/async/index.js
index 12bcb25c37..ab639cc882 100644
--- a/examples/async/index.js
+++ b/examples/async/index.js
@@ -1,15 +1,15 @@
-import 'babel-polyfill'
-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 'babel-polyfill';
+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(
,
document.getElementById('root')
-)
+);
diff --git a/examples/async/reducers/index.js b/examples/async/reducers/index.js
index f936cbced3..d79c407a33 100644
--- a/examples/async/reducers/index.js
+++ b/examples/async/reducers/index.js
@@ -1,42 +1,42 @@
-import { combineReducers } from 'redux'
+import { combineReducers } from 'redux';
import {
SELECT_REDDIT, INVALIDATE_REDDIT,
- REQUEST_POSTS, RECEIVE_POSTS
-} from '../actions'
+ REQUEST_POSTS, RECEIVE_POSTS,
+} from '../actions';
function selectedReddit(state = 'reactjs', action) {
switch (action.type) {
case SELECT_REDDIT:
- return action.reddit
+ return action.reddit;
default:
- return state
+ return state;
}
}
function posts(state = {
isFetching: false,
didInvalidate: false,
- items: []
+ items: [],
}, action) {
switch (action.type) {
case INVALIDATE_REDDIT:
return Object.assign({}, state, {
- didInvalidate: true
- })
+ didInvalidate: true,
+ });
case REQUEST_POSTS:
return Object.assign({}, state, {
isFetching: true,
- didInvalidate: false
- })
+ didInvalidate: false,
+ });
case RECEIVE_POSTS:
return Object.assign({}, state, {
isFetching: false,
didInvalidate: false,
items: action.posts,
- lastUpdated: action.receivedAt
- })
+ lastUpdated: action.receivedAt,
+ });
default:
- return state
+ return state;
}
}
@@ -46,16 +46,16 @@ function postsByReddit(state = { }, action) {
case RECEIVE_POSTS:
case REQUEST_POSTS:
return Object.assign({}, state, {
- [action.reddit]: posts(state[action.reddit], action)
- })
+ [action.reddit]: posts(state[action.reddit], action),
+ });
default:
- return state
+ return state;
}
}
const rootReducer = combineReducers({
postsByReddit,
- selectedReddit
-})
+ selectedReddit,
+});
-export default rootReducer
+export default rootReducer;
diff --git a/examples/async/store/configureStore.js b/examples/async/store/configureStore.js
index 465d94919a..8767d763e7 100644
--- a/examples/async/store/configureStore.js
+++ b/examples/async/store/configureStore.js
@@ -1,22 +1,22 @@
-import { createStore, applyMiddleware } from 'redux'
-import thunkMiddleware from 'redux-thunk'
-import createLogger from 'redux-logger'
-import rootReducer from '../reducers'
+import { createStore, applyMiddleware } from 'redux';
+import thunkMiddleware from 'redux-thunk';
+import createLogger from 'redux-logger';
+import rootReducer from '../reducers';
export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
applyMiddleware(thunkMiddleware, createLogger())
- )
+ );
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
- const nextRootReducer = require('../reducers').default
- store.replaceReducer(nextRootReducer)
- })
+ const nextRootReducer = require('../reducers').default;
+ store.replaceReducer(nextRootReducer);
+ });
}
- return store
+ return store;
}
diff --git a/examples/buildAll.js b/examples/buildAll.js
index 82388984b0..6cd8ed73cf 100644
--- a/examples/buildAll.js
+++ b/examples/buildAll.js
@@ -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()
-})
+const exampleDirs = fs.readdirSync(__dirname).filter((file) =>
+ 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' ] }
-]
+const cmdArgs = [
+ { 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 = {}
+ stdio: 'inherit',
+ };
+ 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');
}
}
}
diff --git a/examples/counter/components/Counter.js b/examples/counter/components/Counter.js
index ef473bf933..0007289e2a 100644
--- a/examples/counter/components/Counter.js
+++ b/examples/counter/components/Counter.js
@@ -1,24 +1,24 @@
-import React, { Component, PropTypes } from 'react'
+import React, { Component, PropTypes } from 'react';
class Counter extends Component {
constructor(props) {
- super(props)
- this.incrementAsync = this.incrementAsync.bind(this)
- this.incrementIfOdd = this.incrementIfOdd.bind(this)
+ super(props);
+ this.incrementAsync = this.incrementAsync.bind(this);
+ this.incrementIfOdd = this.incrementIfOdd.bind(this);
}
incrementIfOdd() {
if (this.props.value % 2 !== 0) {
- this.props.onIncrement()
+ this.props.onIncrement();
}
}
incrementAsync() {
- setTimeout(this.props.onIncrement, 1000)
+ setTimeout(this.props.onIncrement, 1000);
}
render() {
- const { value, onIncrement, onDecrement } = this.props
+ const { value, onIncrement, onDecrement } = this.props;
return (
Clicked: {value} times
@@ -39,14 +39,14 @@ class Counter extends Component {
Increment async
- )
+ );
}
}
Counter.propTypes = {
value: PropTypes.number.isRequired,
onIncrement: PropTypes.func.isRequired,
- onDecrement: PropTypes.func.isRequired
-}
+ onDecrement: PropTypes.func.isRequired,
+};
-export default Counter
+export default Counter;
diff --git a/examples/counter/index.js b/examples/counter/index.js
index 60cac9cf27..8b18cc420f 100644
--- a/examples/counter/index.js
+++ b/examples/counter/index.js
@@ -1,11 +1,11 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { createStore } from 'redux'
-import Counter from './components/Counter'
-import counter from './reducers'
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { createStore } from 'redux';
+import Counter from './components/Counter';
+import counter from './reducers';
-const store = createStore(counter)
-const rootEl = document.getElementById('root')
+const store = createStore(counter);
+const rootEl = document.getElementById('root');
function render() {
ReactDOM.render(
@@ -14,9 +14,9 @@ function render() {
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
/>,
- rootEl
- )
+ rootEl
+ );
}
-render()
-store.subscribe(render)
+render();
+store.subscribe(render);
diff --git a/examples/counter/reducers/index.js b/examples/counter/reducers/index.js
index 49590e9b05..b59edeb76a 100644
--- a/examples/counter/reducers/index.js
+++ b/examples/counter/reducers/index.js
@@ -1,10 +1,10 @@
export default function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
- return state + 1
+ return state + 1;
case 'DECREMENT':
- return state - 1
+ return state - 1;
default:
- return state
+ return state;
}
}
diff --git a/examples/counter/test/components/Counter.spec.js b/examples/counter/test/components/Counter.spec.js
index 4e5258d0ad..874d835136 100644
--- a/examples/counter/test/components/Counter.spec.js
+++ b/examples/counter/test/components/Counter.spec.js
@@ -1,67 +1,67 @@
-import expect from 'expect'
-import React from 'react'
-import { shallow } from 'enzyme'
-import Counter from '../../components/Counter'
+import expect from 'expect';
+import React from 'react';
+import { shallow } from 'enzyme';
+import Counter from '../../components/Counter';
function setup(value = 0) {
const actions = {
onIncrement: expect.createSpy(),
- onDecrement: expect.createSpy()
- }
+ onDecrement: expect.createSpy(),
+ };
const component = shallow(
- )
+ );
return {
- component: component,
- actions: actions,
+ component,
+ actions,
buttons: component.find('button'),
- p: component.find('p')
- }
+ p: component.find('p'),
+ };
}
describe('Counter component', () => {
it('should display count', () => {
- const { p } = setup()
- expect(p.text()).toMatch(/^Clicked: 0 times/)
- })
+ const { p } = setup();
+ expect(p.text()).toMatch(/^Clicked: 0 times/);
+ });
it('first button should call onIncrement', () => {
- const { buttons, actions } = setup()
- buttons.at(0).simulate('click')
- expect(actions.onIncrement).toHaveBeenCalled()
- })
+ const { buttons, actions } = setup();
+ buttons.at(0).simulate('click');
+ expect(actions.onIncrement).toHaveBeenCalled();
+ });
it('second button should call onDecrement', () => {
- const { buttons, actions } = setup()
- buttons.at(1).simulate('click')
- expect(actions.onDecrement).toHaveBeenCalled()
- })
+ const { buttons, actions } = setup();
+ buttons.at(1).simulate('click');
+ expect(actions.onDecrement).toHaveBeenCalled();
+ });
it('third button should not call onIncrement if the counter is even', () => {
- const { buttons, actions } = setup(42)
- buttons.at(2).simulate('click')
- expect(actions.onIncrement).toNotHaveBeenCalled()
- })
+ const { buttons, actions } = setup(42);
+ buttons.at(2).simulate('click');
+ expect(actions.onIncrement).toNotHaveBeenCalled();
+ });
it('third button should call onIncrement if the counter is odd', () => {
- const { buttons, actions } = setup(43)
- buttons.at(2).simulate('click')
- expect(actions.onIncrement).toHaveBeenCalled()
- })
+ const { buttons, actions } = setup(43);
+ buttons.at(2).simulate('click');
+ expect(actions.onIncrement).toHaveBeenCalled();
+ });
it('third button should call onIncrement if the counter is odd and negative', () => {
- const { buttons, actions } = setup(-43)
- buttons.at(2).simulate('click')
- expect(actions.onIncrement).toHaveBeenCalled()
- })
+ const { buttons, actions } = setup(-43);
+ buttons.at(2).simulate('click');
+ expect(actions.onIncrement).toHaveBeenCalled();
+ });
it('fourth button should call onIncrement in a second', (done) => {
- const { buttons, actions } = setup()
- buttons.at(3).simulate('click')
+ const { buttons, actions } = setup();
+ buttons.at(3).simulate('click');
setTimeout(() => {
- expect(actions.onIncrement).toHaveBeenCalled()
- done()
- }, 1000)
- })
-})
+ expect(actions.onIncrement).toHaveBeenCalled();
+ done();
+ }, 1000);
+ });
+});
diff --git a/examples/counter/test/reducers/counter.spec.js b/examples/counter/test/reducers/counter.spec.js
index c51d16adf4..411990c547 100644
--- a/examples/counter/test/reducers/counter.spec.js
+++ b/examples/counter/test/reducers/counter.spec.js
@@ -1,22 +1,22 @@
-import expect from 'expect'
-import counter from '../../reducers'
+import expect from 'expect';
+import counter from '../../reducers';
describe('reducers', () => {
describe('counter', () => {
it('should provide the initial state', () => {
- expect(counter(undefined, {})).toBe(0)
- })
+ expect(counter(undefined, {})).toBe(0);
+ });
it('should handle INCREMENT action', () => {
- expect(counter(1, { type: 'INCREMENT' })).toBe(2)
- })
+ expect(counter(1, { type: 'INCREMENT' })).toBe(2);
+ });
it('should handle DECREMENT action', () => {
- expect(counter(1, { type: 'DECREMENT' })).toBe(0)
- })
+ expect(counter(1, { type: 'DECREMENT' })).toBe(0);
+ });
it('should ignore unknown actions', () => {
- expect(counter(1, { type: 'unknown' })).toBe(1)
- })
- })
-})
+ expect(counter(1, { type: 'unknown' })).toBe(1);
+ });
+ });
+});
diff --git a/examples/real-world/actions/index.js b/examples/real-world/actions/index.js
index 2692fcb069..78961be66e 100644
--- a/examples/real-world/actions/index.js
+++ b/examples/real-world/actions/index.js
@@ -1,66 +1,66 @@
-import { CALL_API, Schemas } from '../middleware/api'
+import { CALL_API, Schemas } from '../middleware/api';
-export const USER_REQUEST = 'USER_REQUEST'
-export const USER_SUCCESS = 'USER_SUCCESS'
-export const USER_FAILURE = 'USER_FAILURE'
+export const USER_REQUEST = 'USER_REQUEST';
+export const USER_SUCCESS = 'USER_SUCCESS';
+export const USER_FAILURE = 'USER_FAILURE';
// Fetches a single user from Github API.
// Relies on the custom API middleware defined in ../middleware/api.js.
function fetchUser(login) {
return {
[CALL_API]: {
- types: [ USER_REQUEST, USER_SUCCESS, USER_FAILURE ],
+ types: [USER_REQUEST, USER_SUCCESS, USER_FAILURE],
endpoint: `users/${login}`,
- schema: Schemas.USER
- }
- }
+ schema: Schemas.USER,
+ },
+ };
}
// Fetches a single user from Github API unless it is cached.
// Relies on Redux Thunk middleware.
export function loadUser(login, requiredFields = []) {
return (dispatch, getState) => {
- const user = getState().entities.users[login]
+ const user = getState().entities.users[login];
if (user && requiredFields.every(key => user.hasOwnProperty(key))) {
- return null
+ return null;
}
- return dispatch(fetchUser(login))
- }
+ return dispatch(fetchUser(login));
+ };
}
-export const REPO_REQUEST = 'REPO_REQUEST'
-export const REPO_SUCCESS = 'REPO_SUCCESS'
-export const REPO_FAILURE = 'REPO_FAILURE'
+export const REPO_REQUEST = 'REPO_REQUEST';
+export const REPO_SUCCESS = 'REPO_SUCCESS';
+export const REPO_FAILURE = 'REPO_FAILURE';
// Fetches a single repository from Github API.
// Relies on the custom API middleware defined in ../middleware/api.js.
function fetchRepo(fullName) {
return {
[CALL_API]: {
- types: [ REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE ],
+ types: [REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE],
endpoint: `repos/${fullName}`,
- schema: Schemas.REPO
- }
- }
+ schema: Schemas.REPO,
+ },
+ };
}
// Fetches a single repository from Github API unless it is cached.
// Relies on Redux Thunk middleware.
export function loadRepo(fullName, requiredFields = []) {
return (dispatch, getState) => {
- const repo = getState().entities.repos[fullName]
+ const repo = getState().entities.repos[fullName];
if (repo && requiredFields.every(key => repo.hasOwnProperty(key))) {
- return null
+ return null;
}
- return dispatch(fetchRepo(fullName))
- }
+ return dispatch(fetchRepo(fullName));
+ };
}
-export const STARRED_REQUEST = 'STARRED_REQUEST'
-export const STARRED_SUCCESS = 'STARRED_SUCCESS'
-export const STARRED_FAILURE = 'STARRED_FAILURE'
+export const STARRED_REQUEST = 'STARRED_REQUEST';
+export const STARRED_SUCCESS = 'STARRED_SUCCESS';
+export const STARRED_FAILURE = 'STARRED_FAILURE';
// Fetches a page of starred repos by a particular user.
// Relies on the custom API middleware defined in ../middleware/api.js.
@@ -68,11 +68,11 @@ function fetchStarred(login, nextPageUrl) {
return {
login,
[CALL_API]: {
- types: [ STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE ],
+ types: [STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE],
endpoint: nextPageUrl,
- schema: Schemas.REPO_ARRAY
- }
- }
+ schema: Schemas.REPO_ARRAY,
+ },
+ };
}
// Fetches a page of starred repos by a particular user.
@@ -82,20 +82,20 @@ export function loadStarred(login, nextPage) {
return (dispatch, getState) => {
const {
nextPageUrl = `users/${login}/starred`,
- pageCount = 0
- } = getState().pagination.starredByUser[login] || {}
+ pageCount = 0,
+ } = getState().pagination.starredByUser[login] || {};
if (pageCount > 0 && !nextPage) {
- return null
+ return null;
}
- return dispatch(fetchStarred(login, nextPageUrl))
- }
+ return dispatch(fetchStarred(login, nextPageUrl));
+ };
}
-export const STARGAZERS_REQUEST = 'STARGAZERS_REQUEST'
-export const STARGAZERS_SUCCESS = 'STARGAZERS_SUCCESS'
-export const STARGAZERS_FAILURE = 'STARGAZERS_FAILURE'
+export const STARGAZERS_REQUEST = 'STARGAZERS_REQUEST';
+export const STARGAZERS_SUCCESS = 'STARGAZERS_SUCCESS';
+export const STARGAZERS_FAILURE = 'STARGAZERS_FAILURE';
// Fetches a page of stargazers for a particular repo.
// Relies on the custom API middleware defined in ../middleware/api.js.
@@ -103,11 +103,11 @@ function fetchStargazers(fullName, nextPageUrl) {
return {
fullName,
[CALL_API]: {
- types: [ STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE ],
+ types: [STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE],
endpoint: nextPageUrl,
- schema: Schemas.USER_ARRAY
- }
- }
+ schema: Schemas.USER_ARRAY,
+ },
+ };
}
// Fetches a page of stargazers for a particular repo.
@@ -117,22 +117,22 @@ export function loadStargazers(fullName, nextPage) {
return (dispatch, getState) => {
const {
nextPageUrl = `repos/${fullName}/stargazers`,
- pageCount = 0
- } = getState().pagination.stargazersByRepo[fullName] || {}
+ pageCount = 0,
+ } = getState().pagination.stargazersByRepo[fullName] || {};
if (pageCount > 0 && !nextPage) {
- return null
+ return null;
}
- return dispatch(fetchStargazers(fullName, nextPageUrl))
- }
+ return dispatch(fetchStargazers(fullName, nextPageUrl));
+ };
}
-export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE'
+export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE';
// Resets the currently visible error message.
export function resetErrorMessage() {
return {
- type: RESET_ERROR_MESSAGE
- }
+ type: RESET_ERROR_MESSAGE,
+ };
}
diff --git a/examples/real-world/components/Explore.js b/examples/real-world/components/Explore.js
index e83051d3bb..30bc6e310f 100644
--- a/examples/real-world/components/Explore.js
+++ b/examples/real-world/components/Explore.js
@@ -1,39 +1,39 @@
-import React, { Component, PropTypes } from 'react'
+import React, { Component, PropTypes } from 'react';
-const GITHUB_REPO = 'https://github.com/reactjs/redux'
+const GITHUB_REPO = 'https://github.com/reactjs/redux';
export default class Explore extends Component {
constructor(props) {
- super(props)
- this.handleKeyUp = this.handleKeyUp.bind(this)
- this.handleGoClick = this.handleGoClick.bind(this)
+ super(props);
+ this.handleKeyUp = this.handleKeyUp.bind(this);
+ this.handleGoClick = this.handleGoClick.bind(this);
}
componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
- this.setInputValue(nextProps.value)
+ this.setInputValue(nextProps.value);
}
}
getInputValue() {
- return this.refs.input.value
+ return this.refs.input.value;
}
setInputValue(val) {
// Generally mutating DOM is a bad idea in React components,
// but doing this for a single uncontrolled field is less fuss
// than making it controlled and maintaining a state for it.
- this.refs.input.value = val
+ this.refs.input.value = val;
}
handleKeyUp(e) {
if (e.keyCode === 13) {
- this.handleGoClick()
+ this.handleGoClick();
}
}
handleGoClick() {
- this.props.onChange(this.getInputValue())
+ this.props.onChange(this.getInputValue());
}
render() {
@@ -41,9 +41,10 @@ export default class Explore extends Component {
Type a username or repo full name and hit 'Go':
+ ref="input"
+ defaultValue={this.props.value}
+ onKeyUp={this.handleKeyUp}
+ />
@@ -54,11 +55,11 @@ export default class Explore extends Component {
Move the DevTools with Ctrl+W or hide them with Ctrl+H.