diff --git a/.eslintrc b/.eslintrc
index 5cf245ac5..de7e83749 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,19 +1,15 @@
{
- "extends": "eslint-config-airbnb",
+ "extends": "eslint-config-rackt",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
- "react/jsx-uses-react": 2,
- "react/jsx-uses-vars": 2,
- "react/react-in-jsx-scope": 2,
-
- //Temporarirly disabled due to a possible bug in babel-eslint (todomvc example)
- "block-scoped-var": 0,
- // Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
- "padded-blocks": 0
+ "valid-jsdoc": 2,
+ "react/jsx-uses-react": 1,
+ "react/jsx-no-undef": 2,
+ "react/wrap-multilines": 2
},
"plugins": [
"react"
diff --git a/docs/api.md b/docs/api.md
index 2670794c5..4082326be 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -21,7 +21,7 @@ ReactDOM.render(
,
rootEl
-);
+)
```
##### React Router 0.13
@@ -34,8 +34,8 @@ Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "
,
document.getElementById('root')
- );
-});
+ )
+})
```
##### React Router 1.0
@@ -46,7 +46,7 @@ ReactDOM.render(
...
,
targetEl
-);
+)
```
### `connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])`
@@ -99,7 +99,7 @@ Returns the wrapped component instance. Only available if you pass `{ withRef: t
##### Inject just `dispatch` and don't listen to store
```js
-export default connect()(TodoApp);
+export default connect()(TodoApp)
```
##### Inject `dispatch` and every field in the global state
@@ -109,151 +109,151 @@ export default connect()(TodoApp);
>listen to a relevant slice of the state.
```js
-export default connect(state => state)(TodoApp);
+export default connect(state => state)(TodoApp)
```
##### Inject `dispatch` and `todos`
```js
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
-export default connect(mapStateToProps)(TodoApp);
+export default connect(mapStateToProps)(TodoApp)
```
##### Inject `todos` and all action creators (`addTodo`, `completeTodo`, ...)
```js
-import * as actionCreators from './actionCreators';
+import * as actionCreators from './actionCreators'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
-export default connect(mapStateToProps, actionCreators)(TodoApp);
+export default connect(mapStateToProps, actionCreators)(TodoApp)
```
##### Inject `todos` and all action creators (`addTodo`, `completeTodo`, ...) as `actions`
```js
-import * as actionCreators from './actionCreators';
-import { bindActionCreators } from 'redux';
+import * as actionCreators from './actionCreators'
+import { bindActionCreators } from 'redux'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
- return { actions: bindActionCreators(actionCreators, dispatch) };
+ return { actions: bindActionCreators(actionCreators, dispatch) }
}
-export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
+export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
```
##### Inject `todos` and a specific action creator (`addTodo`)
```js
-import { addTodo } from './actionCreators';
-import { bindActionCreators } from 'redux';
+import { addTodo } from './actionCreators'
+import { bindActionCreators } from 'redux'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
- return bindActionCreators({ addTodo }, dispatch);
+ return bindActionCreators({ addTodo }, dispatch)
}
-export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
+export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
```
##### Inject `todos`, todoActionCreators as `todoActions`, and counterActionCreators as `counterActions`
```js
-import * as todoActionCreators from './todoActionCreators';
-import * as counterActionCreators from './counterActionCreators';
-import { bindActionCreators } from 'redux';
+import * as todoActionCreators from './todoActionCreators'
+import * as counterActionCreators from './counterActionCreators'
+import { bindActionCreators } from 'redux'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
return {
todoActions: bindActionCreators(todoActionCreators, dispatch),
counterActions: bindActionCreators(counterActionCreators, dispatch)
- };
+ }
}
-export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
+export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
```
##### Inject `todos`, and todoActionCreators and counterActionCreators together as `actions`
```js
-import * as todoActionCreators from './todoActionCreators';
-import * as counterActionCreators from './counterActionCreators';
-import { bindActionCreators } from 'redux';
+import * as todoActionCreators from './todoActionCreators'
+import * as counterActionCreators from './counterActionCreators'
+import { bindActionCreators } from 'redux'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(Object.assign({}, todoActionCreators, counterActionCreators), dispatch)
- };
+ }
}
-export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
+export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
```
##### Inject `todos`, and all todoActionCreators and counterActionCreators directly as props
```js
-import * as todoActionCreators from './todoActionCreators';
-import * as counterActionCreators from './counterActionCreators';
-import { bindActionCreators } from 'redux';
+import * as todoActionCreators from './todoActionCreators'
+import * as counterActionCreators from './counterActionCreators'
+import { bindActionCreators } from 'redux'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
- return bindActionCreators(Object.assign({}, todoActionCreators, counterActionCreators), dispatch);
+ return bindActionCreators(Object.assign({}, todoActionCreators, counterActionCreators), dispatch)
}
-export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
+export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
```
##### Inject `todos` of a specific user depending on props
```js
-import * as actionCreators from './actionCreators';
+import * as actionCreators from './actionCreators'
function mapStateToProps(state, ownProps) {
- return { todos: state.todos[ownProps.userId] };
+ return { todos: state.todos[ownProps.userId] }
}
-export default connect(mapStateToProps)(TodoApp);
+export default connect(mapStateToProps)(TodoApp)
```
##### Inject `todos` of a specific user depending on props, and inject `props.userId` into the action
```js
-import * as actionCreators from './actionCreators';
+import * as actionCreators from './actionCreators'
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
function mergeProps(stateProps, dispatchProps, ownProps) {
return Object.assign({}, ownProps, {
todos: stateProps.todos[ownProps.userId],
addTodo: (text) => dispatchProps.addTodo(ownProps.userId, text)
- });
+ })
}
-export default connect(mapStateToProps, actionCreators, mergeProps)(TodoApp);
+export default connect(mapStateToProps, actionCreators, mergeProps)(TodoApp)
```
diff --git a/docs/quick-start.md b/docs/quick-start.md
index 02be890f4..35c205b49 100644
--- a/docs/quick-start.md
+++ b/docs/quick-start.md
@@ -50,7 +50,7 @@ export default class Counter extends Component {
- );
+ )
}
}
```
@@ -64,30 +64,30 @@ We will use the `connect()` function provided by `react-redux` to turn a “dumb
##### `containers/CounterContainer.js`
```js
-import { Component } from 'react';
-import { connect } from 'react-redux';
+import { Component } from 'react'
+import { connect } from 'react-redux'
-import Counter from '../components/Counter';
-import { increment } from '../actionsCreators';
+import Counter from '../components/Counter'
+import { increment } from '../actionsCreators'
// Which part of the Redux global state does our component want to receive as props?
function mapStateToProps(state) {
return {
value: state.counter
- };
+ }
}
// Which action creators does it want to receive by props?
function mapDispatchToProps(dispatch) {
return {
onIncrement: () => dispatch(increment())
- };
+ }
}
export default connect(
mapStateToProps,
mapDispatchToProps
-)(Counter);
+)(Counter)
// You can also pass an object instead of defining `mapDispatchToProps`:
// export default connect(mapStateToProps, CounterActionCreators)(Counter);
@@ -129,9 +129,9 @@ Finally, how do we actually hook it up to the Redux store? We need to create the
The trick is to wrap the whole view hierarchy into a `` from React Redux.
```js
-import ReactDOM from 'react-dom';
-import { Component } from 'react';
-import { Provider } from 'react-redux';
+import ReactDOM from 'react-dom'
+import { Component } from 'react'
+import { Provider } from 'react-redux'
class App extends Component {
render() {
@@ -139,12 +139,12 @@ class App extends Component {
}
}
-const targetEl = document.getElementById('root');
+const targetEl = document.getElementById('root')
ReactDOM.render(
,
targetEl
-);
+)
```
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index ba44eb40d..fcb0bc1af 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -24,8 +24,8 @@ Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "
,
document.getElementById('root')
- );
-});
+ )
+})
```
Nested view:
@@ -33,7 +33,7 @@ Nested view:
```js
render() {
// Keep passing it down
- return ;
+ return
}
```
@@ -52,12 +52,12 @@ If that’s not practical for whatever reason (for example, if you’re using a
```
function mapStateToProps(state) {
- return { todos: state.todos };
+ return { todos: state.todos }
}
export default connect(mapStateToProps, null, null, {
pure: false
-})(TodoApp);
+})(TodoApp)
```
This will remove the assumption that `TodoApp` is pure and cause it to update whenever its parent component renders. Note that this will make your application less performant, so only do this if you have no other option.
diff --git a/package.json b/package.json
index 9d00009be..83110fb21 100644
--- a/package.json
+++ b/package.json
@@ -41,9 +41,9 @@
"babel-core": "^5.8.22",
"babel-eslint": "^3.1.15",
"babel-loader": "^5.3.2",
- "eslint": "^0.23",
- "eslint-config-airbnb": "0.0.6",
- "eslint-plugin-react": "^2.3.0",
+ "eslint": "^1.7.1",
+ "eslint-config-rackt": "1.1.0",
+ "eslint-plugin-react": "^3.6.3",
"expect": "^1.8.0",
"isparta": "^3.0.3",
"istanbul": "^0.3.17",
diff --git a/src/components/Provider.js b/src/components/Provider.js
index 9acd761be..d0e5ed7f0 100644
--- a/src/components/Provider.js
+++ b/src/components/Provider.js
@@ -1,51 +1,51 @@
-import { Component, PropTypes, Children } from 'react';
-import storeShape from '../utils/storeShape';
+import { Component, PropTypes, Children } from 'react'
+import storeShape from '../utils/storeShape'
-let didWarnAboutReceivingStore = false;
+let didWarnAboutReceivingStore = false
function warnAboutReceivingStore() {
if (didWarnAboutReceivingStore) {
- return;
+ return
}
- didWarnAboutReceivingStore = true;
+ didWarnAboutReceivingStore = true
console.error( // eslint-disable-line no-console
' does not support changing `store` on the fly. ' +
'It is most likely that you see this error because you updated to ' +
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
'automatically. See https://github.com/rackt/react-redux/releases/' +
'tag/v2.0.0 for the migration instructions.'
- );
+ )
}
export default class Provider extends Component {
getChildContext() {
- return { store: this.store };
+ return { store: this.store }
}
constructor(props, context) {
- super(props, context);
- this.store = props.store;
+ super(props, context)
+ this.store = props.store
}
componentWillReceiveProps(nextProps) {
- const { store } = this;
- const { store: nextStore } = nextProps;
+ const { store } = this
+ const { store: nextStore } = nextProps
if (store !== nextStore) {
- warnAboutReceivingStore();
+ warnAboutReceivingStore()
}
}
render() {
- let { children } = this.props;
- return Children.only(children);
+ let { children } = this.props
+ return Children.only(children)
}
}
Provider.propTypes = {
store: storeShape.isRequired,
children: PropTypes.element.isRequired
-};
+}
Provider.childContextTypes = {
store: storeShape.isRequired
-};
+}
diff --git a/src/components/connect.js b/src/components/connect.js
index 2d767c741..5b31632d1 100644
--- a/src/components/connect.js
+++ b/src/components/connect.js
@@ -1,125 +1,125 @@
-import React, { Component } from 'react';
-import storeShape from '../utils/storeShape';
-import shallowEqual from '../utils/shallowEqual';
-import isPlainObject from '../utils/isPlainObject';
-import wrapActionCreators from '../utils/wrapActionCreators';
-import hoistStatics from 'hoist-non-react-statics';
-import invariant from 'invariant';
-
-const defaultMapStateToProps = () => ({});
-const defaultMapDispatchToProps = dispatch => ({ dispatch });
+import React, { Component } from 'react'
+import storeShape from '../utils/storeShape'
+import shallowEqual from '../utils/shallowEqual'
+import isPlainObject from '../utils/isPlainObject'
+import wrapActionCreators from '../utils/wrapActionCreators'
+import hoistStatics from 'hoist-non-react-statics'
+import invariant from 'invariant'
+
+const defaultMapStateToProps = () => ({})
+const defaultMapDispatchToProps = dispatch => ({ dispatch })
const defaultMergeProps = (stateProps, dispatchProps, parentProps) => ({
...parentProps,
...stateProps,
...dispatchProps
-});
+})
function getDisplayName(WrappedComponent) {
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component'
}
// Helps track hot reloading.
-let nextVersion = 0;
+let nextVersion = 0
export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
- const shouldSubscribe = Boolean(mapStateToProps);
- const finalMapStateToProps = mapStateToProps || defaultMapStateToProps;
+ const shouldSubscribe = Boolean(mapStateToProps)
+ const finalMapStateToProps = mapStateToProps || defaultMapStateToProps
const finalMapDispatchToProps = isPlainObject(mapDispatchToProps) ?
wrapActionCreators(mapDispatchToProps) :
- mapDispatchToProps || defaultMapDispatchToProps;
- const finalMergeProps = mergeProps || defaultMergeProps;
- const shouldUpdateStateProps = finalMapStateToProps.length > 1;
- const shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1;
- const { pure = true, withRef = false } = options;
+ mapDispatchToProps || defaultMapDispatchToProps
+ const finalMergeProps = mergeProps || defaultMergeProps
+ const shouldUpdateStateProps = finalMapStateToProps.length > 1
+ const shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1
+ const { pure = true, withRef = false } = options
// Helps track hot reloading.
- const version = nextVersion++;
+ const version = nextVersion++
function computeStateProps(store, props) {
- const state = store.getState();
+ const state = store.getState()
const stateProps = shouldUpdateStateProps ?
finalMapStateToProps(state, props) :
- finalMapStateToProps(state);
+ finalMapStateToProps(state)
invariant(
isPlainObject(stateProps),
'`mapStateToProps` must return an object. Instead received %s.',
stateProps
- );
- return stateProps;
+ )
+ return stateProps
}
function computeDispatchProps(store, props) {
- const { dispatch } = store;
+ const { dispatch } = store
const dispatchProps = shouldUpdateDispatchProps ?
finalMapDispatchToProps(dispatch, props) :
- finalMapDispatchToProps(dispatch);
+ finalMapDispatchToProps(dispatch)
invariant(
isPlainObject(dispatchProps),
'`mapDispatchToProps` must return an object. Instead received %s.',
dispatchProps
- );
- return dispatchProps;
+ )
+ return dispatchProps
}
function computeNextState(stateProps, dispatchProps, parentProps) {
- const mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps);
+ const mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps)
invariant(
isPlainObject(mergedProps),
'`mergeProps` must return an object. Instead received %s.',
mergedProps
- );
- return mergedProps;
+ )
+ return mergedProps
}
return function wrapWithConnect(WrappedComponent) {
class Connect extends Component {
shouldComponentUpdate(nextProps, nextState) {
if (!pure) {
- this.updateStateProps(nextProps);
- this.updateDispatchProps(nextProps);
- this.updateState(nextProps);
- return true;
+ this.updateStateProps(nextProps)
+ this.updateDispatchProps(nextProps)
+ this.updateState(nextProps)
+ return true
}
- const storeChanged = nextState.storeState !== this.state.storeState;
- const propsChanged = !shallowEqual(nextProps, this.props);
- let mapStateProducedChange = false;
- let dispatchPropsChanged = false;
+ const storeChanged = nextState.storeState !== this.state.storeState
+ const propsChanged = !shallowEqual(nextProps, this.props)
+ let mapStateProducedChange = false
+ let dispatchPropsChanged = false
if (storeChanged || (propsChanged && shouldUpdateStateProps)) {
- mapStateProducedChange = this.updateStateProps(nextProps);
+ mapStateProducedChange = this.updateStateProps(nextProps)
}
if (propsChanged && shouldUpdateDispatchProps) {
- dispatchPropsChanged = this.updateDispatchProps(nextProps);
+ dispatchPropsChanged = this.updateDispatchProps(nextProps)
}
if (propsChanged || mapStateProducedChange || dispatchPropsChanged) {
- this.updateState(nextProps);
- return true;
+ this.updateState(nextProps)
+ return true
}
- return false;
+ return false
}
constructor(props, context) {
- super(props, context);
- this.version = version;
- this.store = props.store || context.store;
+ super(props, context)
+ this.version = version
+ this.store = props.store || context.store
invariant(this.store,
`Could not find "store" in either the context or ` +
`props of "${this.constructor.displayName}". ` +
`Either wrap the root component in a , ` +
`or explicitly pass "store" as a prop to "${this.constructor.displayName}".`
- );
+ )
- this.stateProps = computeStateProps(this.store, props);
- this.dispatchProps = computeDispatchProps(this.store, props);
- this.state = { storeState: null };
- this.updateState();
+ this.stateProps = computeStateProps(this.store, props)
+ this.dispatchProps = computeDispatchProps(this.store, props)
+ this.state = { storeState: null }
+ this.updateState()
}
computeNextState(props = this.props) {
@@ -127,112 +127,112 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
this.stateProps,
this.dispatchProps,
props
- );
+ )
}
updateStateProps(props = this.props) {
- const nextStateProps = computeStateProps(this.store, props);
+ const nextStateProps = computeStateProps(this.store, props)
if (shallowEqual(nextStateProps, this.stateProps)) {
- return false;
+ return false
}
- this.stateProps = nextStateProps;
- return true;
+ this.stateProps = nextStateProps
+ return true
}
updateDispatchProps(props = this.props) {
- const nextDispatchProps = computeDispatchProps(this.store, props);
+ const nextDispatchProps = computeDispatchProps(this.store, props)
if (shallowEqual(nextDispatchProps, this.dispatchProps)) {
- return false;
+ return false
}
- this.dispatchProps = nextDispatchProps;
- return true;
+ this.dispatchProps = nextDispatchProps
+ return true
}
updateState(props = this.props) {
- this.nextState = this.computeNextState(props);
+ this.nextState = this.computeNextState(props)
}
isSubscribed() {
- return typeof this.unsubscribe === 'function';
+ return typeof this.unsubscribe === 'function'
}
trySubscribe() {
if (shouldSubscribe && !this.unsubscribe) {
- this.unsubscribe = this.store.subscribe(::this.handleChange);
- this.handleChange();
+ this.unsubscribe = this.store.subscribe(::this.handleChange)
+ this.handleChange()
}
}
tryUnsubscribe() {
if (this.unsubscribe) {
- this.unsubscribe();
- this.unsubscribe = null;
+ this.unsubscribe()
+ this.unsubscribe = null
}
}
componentDidMount() {
- this.trySubscribe();
+ this.trySubscribe()
}
componentWillUnmount() {
- this.tryUnsubscribe();
+ this.tryUnsubscribe()
}
handleChange() {
if (!this.unsubscribe) {
- return;
+ return
}
this.setState({
storeState: this.store.getState()
- });
+ })
}
getWrappedInstance() {
invariant(withRef,
`To access the wrapped instance, you need to specify ` +
`{ withRef: true } as the fourth argument of the connect() call.`
- );
+ )
- return this.refs.wrappedInstance;
+ return this.refs.wrappedInstance
}
render() {
- const ref = withRef ? 'wrappedInstance' : null;
+ const ref = withRef ? 'wrappedInstance' : null
return (
- );
+ )
}
}
- Connect.displayName = `Connect(${getDisplayName(WrappedComponent)})`;
- Connect.WrappedComponent = WrappedComponent;
+ Connect.displayName = `Connect(${getDisplayName(WrappedComponent)})`
+ Connect.WrappedComponent = WrappedComponent
Connect.contextTypes = {
store: storeShape
- };
+ }
Connect.propTypes = {
store: storeShape
- };
+ }
if (process.env.NODE_ENV !== 'production') {
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
if (this.version === version) {
- return;
+ return
}
// We are hot reloading!
- this.version = version;
+ this.version = version
// Update the state and bindings.
- this.trySubscribe();
- this.updateStateProps();
- this.updateDispatchProps();
- this.updateState();
- };
+ this.trySubscribe()
+ this.updateStateProps()
+ this.updateDispatchProps()
+ this.updateState()
+ }
}
- return hoistStatics(Connect, WrappedComponent);
- };
+ return hoistStatics(Connect, WrappedComponent)
+ }
}
diff --git a/src/index.js b/src/index.js
index 5fb3e1b61..046685da4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,2 +1,2 @@
-export { default as Provider } from './components/Provider';
-export { default as connect } from './components/connect';
+export { default as Provider } from './components/Provider'
+export { default as connect } from './components/connect'
diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js
index da6b78cf2..cb8e86144 100644
--- a/src/utils/isPlainObject.js
+++ b/src/utils/isPlainObject.js
@@ -1,4 +1,4 @@
-const fnToString = (fn) => Function.prototype.toString.call(fn);
+const fnToString = (fn) => Function.prototype.toString.call(fn)
/**
* @param {any} obj The object to inspect.
@@ -6,20 +6,20 @@ const fnToString = (fn) => Function.prototype.toString.call(fn);
*/
export default function isPlainObject(obj) {
if (!obj || typeof obj !== 'object') {
- return false;
+ return false
}
const proto = typeof obj.constructor === 'function' ?
Object.getPrototypeOf(obj) :
- Object.prototype;
+ Object.prototype
if (proto === null) {
- return true;
+ return true
}
- const constructor = proto.constructor;
+ const constructor = proto.constructor
return typeof constructor === 'function'
&& constructor instanceof constructor
- && fnToString(constructor) === fnToString(Object);
+ && fnToString(constructor) === fnToString(Object)
}
diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js
index f82be7194..76df37841 100644
--- a/src/utils/shallowEqual.js
+++ b/src/utils/shallowEqual.js
@@ -1,23 +1,23 @@
export default function shallowEqual(objA, objB) {
if (objA === objB) {
- return true;
+ return true
}
- const keysA = Object.keys(objA);
- const keysB = Object.keys(objB);
+ const keysA = Object.keys(objA)
+ const keysB = Object.keys(objB)
if (keysA.length !== keysB.length) {
- return false;
+ return false
}
// Test for A's keys different from B.
- const hasOwn = Object.prototype.hasOwnProperty;
+ const hasOwn = Object.prototype.hasOwnProperty
for (let i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) ||
objA[keysA[i]] !== objB[keysA[i]]) {
- return false;
+ return false
}
}
- return true;
+ return true
}
diff --git a/src/utils/storeShape.js b/src/utils/storeShape.js
index 040ebf167..16b1b141a 100644
--- a/src/utils/storeShape.js
+++ b/src/utils/storeShape.js
@@ -1,7 +1,7 @@
-import { PropTypes } from 'react';
+import { PropTypes } from 'react'
export default PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired
-});
+})
diff --git a/src/utils/wrapActionCreators.js b/src/utils/wrapActionCreators.js
index 983fbe606..349e03d0f 100644
--- a/src/utils/wrapActionCreators.js
+++ b/src/utils/wrapActionCreators.js
@@ -1,5 +1,5 @@
-import { bindActionCreators } from 'redux';
+import { bindActionCreators } from 'redux'
export default function wrapActionCreators(actionCreators) {
- return dispatch => bindActionCreators(actionCreators, dispatch);
+ return dispatch => bindActionCreators(actionCreators, dispatch)
}
diff --git a/test/components/Provider.spec.js b/test/components/Provider.spec.js
index 154747a03..46422f0a9 100644
--- a/test/components/Provider.spec.js
+++ b/test/components/Provider.spec.js
@@ -1,8 +1,8 @@
-import expect from 'expect';
-import React, { PropTypes, Component } from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { createStore } from 'redux';
-import { Provider } from '../../src/index';
+import expect from 'expect'
+import React, { PropTypes, Component } from 'react'
+import TestUtils from 'react-addons-test-utils'
+import { createStore } from 'redux'
+import { Provider } from '../../src/index'
describe('React', () => {
describe('Provider', () => {
@@ -12,97 +12,97 @@ describe('React', () => {
}
render() {
- return ;
+ return
}
}
it('should enforce a single child', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
// Ignore propTypes warnings
- const propTypes = Provider.propTypes;
- Provider.propTypes = {};
+ const propTypes = Provider.propTypes
+ Provider.propTypes = {}
try {
expect(() => TestUtils.renderIntoDocument(
- )).toNotThrow();
+ )).toNotThrow()
expect(() => TestUtils.renderIntoDocument(
- )).toThrow(/exactly one child/);
+ )).toThrow(/exactly one child/)
expect(() => TestUtils.renderIntoDocument(
- )).toThrow(/exactly one child/);
+ )).toThrow(/exactly one child/)
} finally {
- Provider.propTypes = propTypes;
+ Provider.propTypes = propTypes
}
- });
+ })
it('should add the store to the child context', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
- const spy = expect.spyOn(console, 'error');
+ const spy = expect.spyOn(console, 'error')
const tree = TestUtils.renderIntoDocument(
- );
- spy.destroy();
- expect(spy.calls.length).toBe(0);
+ )
+ spy.destroy()
+ expect(spy.calls.length).toBe(0)
- const child = TestUtils.findRenderedComponentWithType(tree, Child);
- expect(child.context.store).toBe(store);
- });
+ const child = TestUtils.findRenderedComponentWithType(tree, Child)
+ expect(child.context.store).toBe(store)
+ })
it('should warn once when receiving a new store in props', () => {
- const store1 = createStore((state = 10) => state + 1);
- const store2 = createStore((state = 10) => state * 2);
- const store3 = createStore((state = 10) => state * state);
+ const store1 = createStore((state = 10) => state + 1)
+ const store2 = createStore((state = 10) => state * 2)
+ const store3 = createStore((state = 10) => state * state)
class ProviderContainer extends Component {
- state = { store: store1 };
+ state = { store: store1 }
render() {
return (
- );
+ )
}
}
- const container = TestUtils.renderIntoDocument();
- const child = TestUtils.findRenderedComponentWithType(container, Child);
- expect(child.context.store.getState()).toEqual(11);
+ const container = TestUtils.renderIntoDocument()
+ const child = TestUtils.findRenderedComponentWithType(container, Child)
+ expect(child.context.store.getState()).toEqual(11)
- let spy = expect.spyOn(console, 'error');
- container.setState({ store: store2 });
- spy.destroy();
+ let spy = expect.spyOn(console, 'error')
+ container.setState({ store: store2 })
+ spy.destroy()
- expect(child.context.store.getState()).toEqual(11);
- expect(spy.calls.length).toBe(1);
+ expect(child.context.store.getState()).toEqual(11)
+ expect(spy.calls.length).toBe(1)
expect(spy.calls[0].arguments[0]).toBe(
' does not support changing `store` on the fly. ' +
'It is most likely that you see this error because you updated to ' +
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
'automatically. See https://github.com/rackt/react-redux/releases/' +
'tag/v2.0.0 for the migration instructions.'
- );
+ )
- spy = expect.spyOn(console, 'error');
- container.setState({ store: store3 });
- spy.destroy();
+ spy = expect.spyOn(console, 'error')
+ container.setState({ store: store3 })
+ spy.destroy()
- expect(child.context.store.getState()).toEqual(11);
- expect(spy.calls.length).toBe(0);
- });
- });
-});
+ expect(child.context.store.getState()).toEqual(11)
+ expect(spy.calls.length).toBe(0)
+ })
+ })
+})
diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js
index 08f6b219f..bae556e0a 100644
--- a/test/components/connect.spec.js
+++ b/test/components/connect.spec.js
@@ -1,15 +1,15 @@
-import expect from 'expect';
-import React, { createClass, Children, PropTypes, Component } from 'react';
-import ReactDOM from 'react-dom';
-import TestUtils from 'react-addons-test-utils';
-import { createStore } from 'redux';
-import { connect } from '../../src/index';
+import expect from 'expect'
+import React, { createClass, Children, PropTypes, Component } from 'react'
+import ReactDOM from 'react-dom'
+import TestUtils from 'react-addons-test-utils'
+import { createStore } from 'redux'
+import { connect } from '../../src/index'
describe('React', () => {
describe('connect', () => {
class Passthrough extends Component {
render() {
- return ;
+ return
}
}
@@ -19,27 +19,27 @@ describe('React', () => {
}
getChildContext() {
- return { store: this.props.store };
+ return { store: this.props.store }
}
render() {
- return Children.only(this.props.children);
+ return Children.only(this.props.children)
}
}
function stringBuilder(prev = '', action) {
return action.type === 'APPEND'
? prev + action.body
- : prev;
+ : prev
}
it('should receive the store in the context', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
@connect()
class Container extends Component {
render() {
- return ;
+ return
}
}
@@ -47,48 +47,48 @@ describe('React', () => {
- );
+ )
- const container = TestUtils.findRenderedComponentWithType(tree, Container);
- expect(container.context.store).toBe(store);
- });
+ const container = TestUtils.findRenderedComponentWithType(tree, Container)
+ expect(container.context.store).toBe(store)
+ })
it('should pass state and props to the given component', () => {
const store = createStore(() => ({
foo: 'bar',
baz: 42,
hello: 'world'
- }));
+ }))
@connect(({ foo, baz }) => ({ foo, baz }))
class Container extends Component {
render() {
- return ;
+ return
}
}
const container = TestUtils.renderIntoDocument(
-
+
- );
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.pass).toEqual('through');
- expect(stub.props.foo).toEqual('bar');
- expect(stub.props.baz).toEqual(42);
- expect(stub.props.hello).toEqual(undefined);
+ )
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.pass).toEqual('through')
+ expect(stub.props.foo).toEqual('bar')
+ expect(stub.props.baz).toEqual(42)
+ expect(stub.props.hello).toEqual(undefined)
expect(() =>
TestUtils.findRenderedComponentWithType(container, Container)
- ).toNotThrow();
- });
+ ).toNotThrow()
+ })
it('should subscribe class components to the store changes', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
@connect(state => ({ string: state }) )
class Container extends Component {
render() {
- return ;
+ return
}
}
@@ -96,53 +96,53 @@ describe('React', () => {
- );
+ )
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(stub.props.string).toBe('');
- store.dispatch({ type: 'APPEND', body: 'a'});
- expect(stub.props.string).toBe('a');
- store.dispatch({ type: 'APPEND', body: 'b'});
- expect(stub.props.string).toBe('ab');
- });
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(stub.props.string).toBe('')
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ expect(stub.props.string).toBe('a')
+ store.dispatch({ type: 'APPEND', body: 'b' })
+ expect(stub.props.string).toBe('ab')
+ })
it('should subscribe pure function components to the store changes', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
let Container = connect(
state => ({ string: state })
)(function Container(props) {
- return ;
- });
+ return
+ })
- const spy = expect.spyOn(console, 'error');
+ const spy = expect.spyOn(console, 'error')
const tree = TestUtils.renderIntoDocument(
- );
- spy.destroy();
- expect(spy.calls.length).toBe(0);
-
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(stub.props.string).toBe('');
- store.dispatch({ type: 'APPEND', body: 'a'});
- expect(stub.props.string).toBe('a');
- store.dispatch({ type: 'APPEND', body: 'b'});
- expect(stub.props.string).toBe('ab');
- });
+ )
+ spy.destroy()
+ expect(spy.calls.length).toBe(0)
+
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(stub.props.string).toBe('')
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ expect(stub.props.string).toBe('a')
+ store.dispatch({ type: 'APPEND', body: 'b' })
+ expect(stub.props.string).toBe('ab')
+ })
it('should handle dispatches before componentDidMount', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
@connect(state => ({ string: state }) )
class Container extends Component {
componentWillMount() {
- store.dispatch({ type: 'APPEND', body: 'a'});
+ store.dispatch({ type: 'APPEND', body: 'a' })
}
render() {
- return ;
+ return
}
}
@@ -150,40 +150,40 @@ describe('React', () => {
- );
+ )
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(stub.props.string).toBe('a');
- });
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(stub.props.string).toBe('a')
+ })
it('should handle additional prop changes in addition to slice', () => {
const store = createStore(() => ({
foo: 'bar'
- }));
+ }))
@connect(state => state)
class ConnectContainer extends Component {
render() {
return (
- );
+ )
}
}
class Container extends Component {
constructor() {
- super();
+ super()
this.state = {
bar: {
baz: ''
}
- };
+ }
}
componentDidMount() {
this.setState({
bar: Object.assign({}, this.state.bar, { baz: 'through' })
- });
+ })
}
render() {
@@ -191,27 +191,27 @@ describe('React', () => {
- );
+ )
}
}
- const container = TestUtils.renderIntoDocument();
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.foo).toEqual('bar');
- expect(stub.props.pass).toEqual('through');
- });
+ const container = TestUtils.renderIntoDocument()
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.foo).toEqual('bar')
+ expect(stub.props.pass).toEqual('through')
+ })
it('should remove undefined props', () => {
- const store = createStore(() => ({}));
- let props = { x: true };
- let container;
+ const store = createStore(() => ({}))
+ let props = { x: true }
+ let container
@connect(() => ({}), () => ({}))
class ConnectContainer extends Component {
render() {
return (
- );
+ )
}
}
@@ -219,7 +219,7 @@ describe('React', () => {
render() {
return (
- );
+ )
}
}
@@ -227,34 +227,34 @@ describe('React', () => {
container = instance} />
- );
+ )
const propsBefore = {
...TestUtils.findRenderedComponentWithType(container, Passthrough).props
- };
+ }
- props = {};
- container.forceUpdate();
+ props = {}
+ container.forceUpdate()
const propsAfter = {
...TestUtils.findRenderedComponentWithType(container, Passthrough).props
- };
+ }
- expect(propsBefore.x).toEqual(true);
- expect('x' in propsAfter).toEqual(false, 'x prop must be removed');
- });
+ expect(propsBefore.x).toEqual(true)
+ expect('x' in propsAfter).toEqual(false, 'x prop must be removed')
+ })
it('should remove undefined props without mapDispatch', () => {
- const store = createStore(() => ({}));
- let props = { x: true };
- let container;
+ const store = createStore(() => ({}))
+ let props = { x: true }
+ let container
@connect(() => ({}))
class ConnectContainer extends Component {
render() {
return (
- );
+ )
}
}
@@ -262,7 +262,7 @@ describe('React', () => {
render() {
return (
- );
+ )
}
}
@@ -270,53 +270,53 @@ describe('React', () => {
container = instance} />
- );
+ )
const propsBefore = {
...TestUtils.findRenderedComponentWithType(container, Passthrough).props
- };
+ }
- props = {};
- container.forceUpdate();
+ props = {}
+ container.forceUpdate()
const propsAfter = {
...TestUtils.findRenderedComponentWithType(container, Passthrough).props
- };
+ }
- expect(propsBefore.x).toEqual(true);
- expect('x' in propsAfter).toEqual(false, 'x prop must be removed');
- });
+ expect(propsBefore.x).toEqual(true)
+ expect('x' in propsAfter).toEqual(false, 'x prop must be removed')
+ })
it('should ignore deep mutations in props', () => {
const store = createStore(() => ({
foo: 'bar'
- }));
+ }))
@connect(state => state)
class ConnectContainer extends Component {
render() {
return (
- );
+ )
}
}
class Container extends Component {
constructor() {
- super();
+ super()
this.state = {
bar: {
baz: ''
}
- };
+ }
}
componentDidMount() {
// Simulate deep object mutation
- this.state.bar.baz = 'through';
+ this.state.bar.baz = 'through'
this.setState({
bar: this.state.bar
- });
+ })
}
render() {
@@ -324,28 +324,28 @@ describe('React', () => {
- );
+ )
}
}
- const container = TestUtils.renderIntoDocument();
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.foo).toEqual('bar');
- expect(stub.props.pass).toEqual('');
- });
+ const container = TestUtils.renderIntoDocument()
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.foo).toEqual('bar')
+ expect(stub.props.pass).toEqual('')
+ })
it('should allow for merge to incorporate state and prop changes', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
function doSomething(thing) {
return {
type: 'APPEND',
body: thing
- };
+ }
}
@connect(
- state => ({stateThing: state}),
+ state => ({ stateThing: state }),
dispatch => ({
doSomething: (whatever) => dispatch(doSomething(whatever))
}),
@@ -353,21 +353,21 @@ describe('React', () => {
...stateProps,
...actionProps,
mergedDoSomething(thing) {
- const seed = stateProps.stateThing === '' ? 'HELLO ' : '';
- actionProps.doSomething(seed + thing + parentProps.extra);
+ const seed = stateProps.stateThing === '' ? 'HELLO ' : ''
+ actionProps.doSomething(seed + thing + parentProps.extra)
}
})
)
class Container extends Component {
render() {
- return ;
- };
+ return
+ }
}
class OuterContainer extends Component {
constructor() {
- super();
- this.state = { extra: 'z' };
+ super()
+ this.state = { extra: 'z' }
}
render() {
@@ -375,26 +375,26 @@ describe('React', () => {
- );
+ )
}
}
- const tree = TestUtils.renderIntoDocument();
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(stub.props.stateThing).toBe('');
- stub.props.mergedDoSomething('a');
- expect(stub.props.stateThing).toBe('HELLO az');
- stub.props.mergedDoSomething('b');
- expect(stub.props.stateThing).toBe('HELLO azbz');
- tree.setState({extra: 'Z'});
- stub.props.mergedDoSomething('c');
- expect(stub.props.stateThing).toBe('HELLO azbzcZ');
- });
+ const tree = TestUtils.renderIntoDocument()
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(stub.props.stateThing).toBe('')
+ stub.props.mergedDoSomething('a')
+ expect(stub.props.stateThing).toBe('HELLO az')
+ stub.props.mergedDoSomething('b')
+ expect(stub.props.stateThing).toBe('HELLO azbz')
+ tree.setState({ extra: 'Z' })
+ stub.props.mergedDoSomething('c')
+ expect(stub.props.stateThing).toBe('HELLO azbzcZ')
+ })
it('should merge actionProps into WrappedComponent', () => {
const store = createStore(() => ({
foo: 'bar'
- }));
+ }))
@connect(
state => state,
@@ -402,48 +402,48 @@ describe('React', () => {
)
class Container extends Component {
render() {
- return ;
+ return
}
}
const container = TestUtils.renderIntoDocument(
-
+
- );
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.dispatch).toEqual(store.dispatch);
- expect(stub.props.foo).toEqual('bar');
+ )
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.dispatch).toEqual(store.dispatch)
+ expect(stub.props.foo).toEqual('bar')
expect(() =>
TestUtils.findRenderedComponentWithType(container, Container)
- ).toNotThrow();
- const decorated = TestUtils.findRenderedComponentWithType(container, Container);
- expect(decorated.isSubscribed()).toBe(true);
- });
+ ).toNotThrow()
+ const decorated = TestUtils.findRenderedComponentWithType(container, Container)
+ expect(decorated.isSubscribed()).toBe(true)
+ })
it('should not invoke mapState when props change if it only has one argument', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
- let invocationCount = 0;
+ let invocationCount = 0
@connect(() => {
- invocationCount++;
- return {};
+ invocationCount++
+ return {}
})
class WithoutProps extends Component {
render() {
- return ;
+ return
}
}
class OuterComponent extends Component {
constructor() {
- super();
- this.state = { foo: 'FOO' };
+ super()
+ this.state = { foo: 'FOO' }
}
setFoo(foo) {
- this.setState({ foo });
+ this.setState({ foo })
}
render() {
@@ -451,47 +451,47 @@ describe('React', () => {
- );
+ )
}
}
- let outerComponent;
+ let outerComponent
TestUtils.renderIntoDocument(
outerComponent = c} />
- );
- outerComponent.setFoo('BAR');
- outerComponent.setFoo('DID');
+ )
+ outerComponent.setFoo('BAR')
+ outerComponent.setFoo('DID')
- expect(invocationCount).toEqual(2);
- });
+ expect(invocationCount).toEqual(2)
+ })
it('should invoke mapState every time props are changed if it has a second argument', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
- let propsPassedIn;
- let invocationCount = 0;
+ let propsPassedIn
+ let invocationCount = 0
@connect((state, props) => {
- invocationCount++;
- propsPassedIn = props;
- return {};
+ invocationCount++
+ propsPassedIn = props
+ return {}
})
class WithProps extends Component {
render() {
- return ;
+ return
}
}
class OuterComponent extends Component {
constructor() {
- super();
- this.state = { foo: 'FOO' };
+ super()
+ this.state = { foo: 'FOO' }
}
setFoo(foo) {
- this.setState({ foo });
+ this.setState({ foo })
}
render() {
@@ -499,49 +499,49 @@ describe('React', () => {
- );
+ )
}
}
- let outerComponent;
+ let outerComponent
TestUtils.renderIntoDocument(
outerComponent = c} />
- );
+ )
- outerComponent.setFoo('BAR');
- outerComponent.setFoo('BAZ');
+ outerComponent.setFoo('BAR')
+ outerComponent.setFoo('BAZ')
- expect(invocationCount).toEqual(4);
+ expect(invocationCount).toEqual(4)
expect(propsPassedIn).toEqual({
foo: 'BAZ'
- });
- });
+ })
+ })
it('should not invoke mapDispatch when props change if it only has one argument', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
- let invocationCount = 0;
+ let invocationCount = 0
@connect(null, () => {
- invocationCount++;
- return {};
+ invocationCount++
+ return {}
})
class WithoutProps extends Component {
render() {
- return ;
+ return
}
}
class OuterComponent extends Component {
constructor() {
- super();
- this.state = { foo: 'FOO' };
+ super()
+ this.state = { foo: 'FOO' }
}
setFoo(foo) {
- this.setState({ foo });
+ this.setState({ foo })
}
render() {
@@ -549,48 +549,48 @@ describe('React', () => {
- );
+ )
}
}
- let outerComponent;
+ let outerComponent
TestUtils.renderIntoDocument(
outerComponent = c} />
- );
+ )
- outerComponent.setFoo('BAR');
- outerComponent.setFoo('DID');
+ outerComponent.setFoo('BAR')
+ outerComponent.setFoo('DID')
- expect(invocationCount).toEqual(1);
- });
+ expect(invocationCount).toEqual(1)
+ })
it('should invoke mapDispatch every time props are changed if it has a second argument', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
- let propsPassedIn;
- let invocationCount = 0;
+ let propsPassedIn
+ let invocationCount = 0
@connect(null, (dispatch, props) => {
- invocationCount++;
- propsPassedIn = props;
- return {};
+ invocationCount++
+ propsPassedIn = props
+ return {}
})
class WithProps extends Component {
render() {
- return ;
+ return
}
}
class OuterComponent extends Component {
constructor() {
- super();
- this.state = { foo: 'FOO' };
+ super()
+ this.state = { foo: 'FOO' }
}
setFoo(foo) {
- this.setState({ foo });
+ this.setState({ foo })
}
render() {
@@ -598,73 +598,73 @@ describe('React', () => {
- );
+ )
}
}
- let outerComponent;
+ let outerComponent
TestUtils.renderIntoDocument(
outerComponent = c} />
- );
+ )
- outerComponent.setFoo('BAR');
- outerComponent.setFoo('BAZ');
+ outerComponent.setFoo('BAR')
+ outerComponent.setFoo('BAZ')
- expect(invocationCount).toEqual(3);
+ expect(invocationCount).toEqual(3)
expect(propsPassedIn).toEqual({
foo: 'BAZ'
- });
- });
+ })
+ })
it('should pass dispatch and avoid subscription if arguments are falsy', () => {
const store = createStore(() => ({
foo: 'bar'
- }));
+ }))
function runCheck(...connectArgs) {
@connect(...connectArgs)
class Container extends Component {
render() {
- return ;
+ return
}
}
const container = TestUtils.renderIntoDocument(
-
+
- );
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.dispatch).toEqual(store.dispatch);
- expect(stub.props.foo).toBe(undefined);
- expect(stub.props.pass).toEqual('through');
+ )
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.dispatch).toEqual(store.dispatch)
+ expect(stub.props.foo).toBe(undefined)
+ expect(stub.props.pass).toEqual('through')
expect(() =>
TestUtils.findRenderedComponentWithType(container, Container)
- ).toNotThrow();
- const decorated = TestUtils.findRenderedComponentWithType(container, Container);
- expect(decorated.isSubscribed()).toBe(false);
+ ).toNotThrow()
+ const decorated = TestUtils.findRenderedComponentWithType(container, Container)
+ expect(decorated.isSubscribed()).toBe(false)
}
- runCheck();
- runCheck(null, null, null);
- runCheck(false, false, false);
- });
+ runCheck()
+ runCheck(null, null, null)
+ runCheck(false, false, false)
+ })
it('should unsubscribe before unmounting', () => {
- const store = createStore(stringBuilder);
- const subscribe = store.subscribe;
+ const store = createStore(stringBuilder)
+ const subscribe = store.subscribe
// Keep track of unsubscribe by wrapping subscribe()
- const spy = expect.createSpy(() => ({}));
+ const spy = expect.createSpy(() => ({}))
store.subscribe = (listener) => {
- const unsubscribe = subscribe(listener);
+ const unsubscribe = subscribe(listener)
return () => {
- spy();
- return unsubscribe();
- };
- };
+ spy()
+ return unsubscribe()
+ }
+ }
@connect(
state => ({ string: state }),
@@ -672,26 +672,26 @@ describe('React', () => {
)
class Container extends Component {
render() {
- return ;
+ return
}
}
- const div = document.createElement('div');
+ const div = document.createElement('div')
ReactDOM.render(
,
div
- );
+ )
- expect(spy.calls.length).toBe(0);
- ReactDOM.unmountComponentAtNode(div);
- expect(spy.calls.length).toBe(1);
- });
+ expect(spy.calls.length).toBe(0)
+ ReactDOM.unmountComponentAtNode(div)
+ expect(spy.calls.length).toBe(1)
+ })
it('should not attempt to set state after unmounting', () => {
- const store = createStore(stringBuilder);
- let mapStateToPropsCalls = 0;
+ const store = createStore(stringBuilder)
+ let mapStateToPropsCalls = 0
@connect(
() => ({ calls: ++mapStateToPropsCalls }),
@@ -699,35 +699,35 @@ describe('React', () => {
)
class Container extends Component {
render() {
- return ;
+ return
}
}
- const div = document.createElement('div');
+ const div = document.createElement('div')
store.subscribe(() =>
ReactDOM.unmountComponentAtNode(div)
- );
+ )
ReactDOM.render(
,
div
- );
+ )
- expect(mapStateToPropsCalls).toBe(2);
- const spy = expect.spyOn(console, 'error');
- store.dispatch({ type: 'APPEND', body: 'a'});
- spy.destroy();
- expect(spy.calls.length).toBe(0);
- expect(mapStateToPropsCalls).toBe(2);
- });
+ expect(mapStateToPropsCalls).toBe(2)
+ const spy = expect.spyOn(console, 'error')
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ spy.destroy()
+ expect(spy.calls.length).toBe(0)
+ expect(mapStateToPropsCalls).toBe(2)
+ })
it('should shallowly compare the selected state to prevent unnecessary updates', () => {
- const store = createStore(stringBuilder);
- const spy = expect.createSpy(() => ({}));
+ const store = createStore(stringBuilder)
+ const spy = expect.createSpy(() => ({}))
function render({ string }) {
- spy();
- return ;
+ spy()
+ return
}
@connect(
@@ -736,7 +736,7 @@ describe('React', () => {
)
class Container extends Component {
render() {
- return render(this.props);
+ return render(this.props)
}
}
@@ -744,25 +744,25 @@ describe('React', () => {
- );
-
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(spy.calls.length).toBe(1);
- expect(stub.props.string).toBe('');
- store.dispatch({ type: 'APPEND', body: 'a'});
- expect(spy.calls.length).toBe(2);
- store.dispatch({ type: 'APPEND', body: 'b'});
- expect(spy.calls.length).toBe(3);
- store.dispatch({ type: 'APPEND', body: ''});
- expect(spy.calls.length).toBe(3);
- });
+ )
+
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(spy.calls.length).toBe(1)
+ expect(stub.props.string).toBe('')
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ expect(spy.calls.length).toBe(2)
+ store.dispatch({ type: 'APPEND', body: 'b' })
+ expect(spy.calls.length).toBe(3)
+ store.dispatch({ type: 'APPEND', body: '' })
+ expect(spy.calls.length).toBe(3)
+ })
it('should shallowly compare the merged state to prevent unnecessary updates', () => {
- const store = createStore(stringBuilder);
- const spy = expect.createSpy(() => ({}));
+ const store = createStore(stringBuilder)
+ const spy = expect.createSpy(() => ({}))
function render({ string, pass }) {
- spy();
- return ;
+ spy()
+ return
}
@connect(
@@ -776,14 +776,14 @@ describe('React', () => {
)
class Container extends Component {
render() {
- return render(this.props);
+ return render(this.props)
}
}
class Root extends Component {
constructor(props) {
- super(props);
- this.state = { pass: '' };
+ super(props)
+ this.state = { pass: '' }
}
render() {
@@ -791,72 +791,72 @@ describe('React', () => {
- );
+ )
}
}
- const tree = TestUtils.renderIntoDocument();
- const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- expect(spy.calls.length).toBe(1);
- expect(stub.props.string).toBe('');
- expect(stub.props.pass).toBe('');
-
- store.dispatch({ type: 'APPEND', body: 'a'});
- expect(spy.calls.length).toBe(2);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe('');
-
- tree.setState({ pass: '' });
- expect(spy.calls.length).toBe(2);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe('');
-
- tree.setState({ pass: 'through' });
- expect(spy.calls.length).toBe(3);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe('through');
-
- tree.setState({ pass: 'through' });
- expect(spy.calls.length).toBe(3);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe('through');
-
- const obj = { prop: 'val' };
- tree.setState({ pass: obj });
- expect(spy.calls.length).toBe(4);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe(obj);
-
- tree.setState({ pass: obj });
- expect(spy.calls.length).toBe(4);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe(obj);
-
- const obj2 = Object.assign({}, obj, { val: 'otherval' });
- tree.setState({ pass: obj2 });
- expect(spy.calls.length).toBe(5);
- expect(stub.props.string).toBe('a');
- expect(stub.props.pass).toBe(obj2);
-
- obj2.val = 'mutation';
- tree.setState({ pass: obj2 });
- expect(spy.calls.length).toBe(5);
- expect(stub.props.string).toBe('a');
- expect(stub.props.passVal).toBe('otherval');
- });
+ const tree = TestUtils.renderIntoDocument()
+ const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ expect(spy.calls.length).toBe(1)
+ expect(stub.props.string).toBe('')
+ expect(stub.props.pass).toBe('')
+
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ expect(spy.calls.length).toBe(2)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe('')
+
+ tree.setState({ pass: '' })
+ expect(spy.calls.length).toBe(2)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe('')
+
+ tree.setState({ pass: 'through' })
+ expect(spy.calls.length).toBe(3)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe('through')
+
+ tree.setState({ pass: 'through' })
+ expect(spy.calls.length).toBe(3)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe('through')
+
+ const obj = { prop: 'val' }
+ tree.setState({ pass: obj })
+ expect(spy.calls.length).toBe(4)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe(obj)
+
+ tree.setState({ pass: obj })
+ expect(spy.calls.length).toBe(4)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe(obj)
+
+ const obj2 = Object.assign({}, obj, { val: 'otherval' })
+ tree.setState({ pass: obj2 })
+ expect(spy.calls.length).toBe(5)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.pass).toBe(obj2)
+
+ obj2.val = 'mutation'
+ tree.setState({ pass: obj2 })
+ expect(spy.calls.length).toBe(5)
+ expect(stub.props.string).toBe('a')
+ expect(stub.props.passVal).toBe('otherval')
+ })
it('should throw an error if mapState, mapDispatch, or mergeProps returns anything but a plain object', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
function makeContainer(mapState, mapDispatch, mergeProps) {
return React.createElement(
@connect(mapState, mapDispatch, mergeProps)
class Container extends Component {
render() {
- return ;
+ return
}
}
- );
+ )
}
function AwesomeMap() { }
@@ -866,76 +866,76 @@ describe('React', () => {
{makeContainer(() => 1, () => ({}), () => ({}))}
- );
- }).toThrow(/mapState/);
+ )
+ }).toThrow(/mapState/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => 'hey', () => ({}), () => ({}))}
- );
- }).toThrow(/mapState/);
+ )
+ }).toThrow(/mapState/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => new AwesomeMap(), () => ({}), () => ({}))}
- );
- }).toThrow(/mapState/);
+ )
+ }).toThrow(/mapState/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => 1, () => ({}))}
- );
- }).toThrow(/mapDispatch/);
+ )
+ }).toThrow(/mapDispatch/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => 'hey', () => ({}))}
- );
- }).toThrow(/mapDispatch/);
+ )
+ }).toThrow(/mapDispatch/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => new AwesomeMap(), () => ({}))}
- );
- }).toThrow(/mapDispatch/);
+ )
+ }).toThrow(/mapDispatch/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => ({}), () => 1)}
- );
- }).toThrow(/mergeProps/);
+ )
+ }).toThrow(/mergeProps/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => ({}), () => 'hey')}
- );
- }).toThrow(/mergeProps/);
+ )
+ }).toThrow(/mergeProps/)
expect(() => {
TestUtils.renderIntoDocument(
{makeContainer(() => ({}), () => ({}), () => new AwesomeMap())}
- );
- }).toThrow(/mergeProps/);
- });
+ )
+ }).toThrow(/mergeProps/)
+ })
it('should recalculate the state and rebind the actions on hot update', () => {
- const store = createStore(() => {});
+ const store = createStore(() => {})
@connect(
null,
@@ -945,7 +945,7 @@ describe('React', () => {
render() {
return (
- );
+ )
}
}
@@ -957,7 +957,7 @@ describe('React', () => {
render() {
return (
- );
+ )
}
}
@@ -969,19 +969,19 @@ describe('React', () => {
render() {
return (
- );
+ )
}
}
- let container;
+ let container
TestUtils.renderIntoDocument(
container = instance} />
- );
- const stub = TestUtils.findRenderedComponentWithType(container, Passthrough);
- expect(stub.props.foo).toEqual(undefined);
- expect(stub.props.scooby).toEqual('doo');
+ )
+ const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
+ expect(stub.props.foo).toEqual(undefined)
+ expect(stub.props.scooby).toEqual('doo')
function imitateHotReloading(TargetClass, SourceClass) {
// Crude imitation of hot reloading that does the job
@@ -989,114 +989,114 @@ describe('React', () => {
typeof SourceClass.prototype[key] === 'function'
).forEach(key => {
if (key !== 'render') {
- TargetClass.prototype[key] = SourceClass.prototype[key];
+ TargetClass.prototype[key] = SourceClass.prototype[key]
}
- });
- container.forceUpdate();
+ })
+ container.forceUpdate()
}
- imitateHotReloading(ContainerBefore, ContainerAfter);
- expect(stub.props.foo).toEqual('baz');
- expect(stub.props.scooby).toEqual('foo');
+ imitateHotReloading(ContainerBefore, ContainerAfter)
+ expect(stub.props.foo).toEqual('baz')
+ expect(stub.props.scooby).toEqual('foo')
- imitateHotReloading(ContainerBefore, ContainerNext);
- expect(stub.props.foo).toEqual('bar');
- expect(stub.props.scooby).toEqual('boo');
- });
+ imitateHotReloading(ContainerBefore, ContainerNext)
+ expect(stub.props.foo).toEqual('bar')
+ expect(stub.props.scooby).toEqual('boo')
+ })
it('should set the displayName correctly', () => {
expect(connect(state => state)(
class Foo extends Component {
render() {
- return ;
+ return
}
}
- ).displayName).toBe('Connect(Foo)');
+ ).displayName).toBe('Connect(Foo)')
expect(connect(state => state)(
createClass({
displayName: 'Bar',
render() {
- return ;
+ return
}
})
- ).displayName).toBe('Connect(Bar)');
+ ).displayName).toBe('Connect(Bar)')
expect(connect(state => state)(
createClass({
render() {
- return ;
+ return
}
})
- ).displayName).toBe('Connect(Component)');
- });
+ ).displayName).toBe('Connect(Component)')
+ })
it('should expose the wrapped component as WrappedComponent', () => {
class Container extends Component {
render() {
- return ;
+ return
}
}
- const decorator = connect(state => state);
- const decorated = decorator(Container);
+ const decorator = connect(state => state)
+ const decorated = decorator(Container)
- expect(decorated.WrappedComponent).toBe(Container);
- });
+ expect(decorated.WrappedComponent).toBe(Container)
+ })
it('should hoist non-react statics from wrapped component', () => {
class Container extends Component {
- static howIsRedux = () => 'Awesome!';
- static foo = 'bar';
+ static howIsRedux = () => 'Awesome!'
+ static foo = 'bar'
render() {
- return ;
+ return
}
}
- const decorator = connect(state => state);
- const decorated = decorator(Container);
+ const decorator = connect(state => state)
+ const decorated = decorator(Container)
- expect(decorated.howIsRedux).toBeA('function');
- expect(decorated.howIsRedux()).toBe('Awesome!');
- expect(decorated.foo).toBe('bar');
- });
+ expect(decorated.howIsRedux).toBeA('function')
+ expect(decorated.howIsRedux()).toBe('Awesome!')
+ expect(decorated.foo).toBe('bar')
+ })
it('should use the store from the props instead of from the context if present', () => {
class Container extends Component {
render() {
- return ;
+ return
}
}
- let actualState;
+ let actualState
- const expectedState = { foos: {} };
+ const expectedState = { foos: {} }
const decorator = connect(state => {
- actualState = state;
- return {};
- });
- const Decorated = decorator(Container);
+ actualState = state
+ return {}
+ })
+ const Decorated = decorator(Container)
const mockStore = {
dispatch: () => {},
subscribe: () => {},
getState: () => expectedState
- };
+ }
- TestUtils.renderIntoDocument();
+ TestUtils.renderIntoDocument()
- expect(actualState).toEqual(expectedState);
- });
+ expect(actualState).toEqual(expectedState)
+ })
it('should throw an error if the store is not in the props or context', () => {
class Container extends Component {
render() {
- return ;
+ return
}
}
- const decorator = connect(() => {});
- const Decorated = decorator(Container);
+ const decorator = connect(() => {})
+ const Decorated = decorator(Container)
expect(() =>
TestUtils.renderIntoDocument()
@@ -1104,185 +1104,185 @@ describe('React', () => {
'Invariant Violation: Could not find "store" in either the context ' +
'or props of "Connect(Container)". Either wrap the root component in a ' +
', or explicitly pass "store" as a prop to "Connect(Container)".'
- );
- });
+ )
+ })
it('should throw when trying to access the wrapped instance if withRef is not specified', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
class Container extends Component {
render() {
- return ;
+ return
}
}
- const decorator = connect(state => state);
- const Decorated = decorator(Container);
+ const decorator = connect(state => state)
+ const Decorated = decorator(Container)
const tree = TestUtils.renderIntoDocument(
- );
+ )
- const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated);
+ const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated)
expect(() => decorated.getWrappedInstance()).toThrow(
/To access the wrapped instance, you need to specify \{ withRef: true \} as the fourth argument of the connect\(\) call\./
- );
- });
+ )
+ })
it('should return the instance of the wrapped component for use in calling child methods', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
const someData = {
some: 'data'
- };
+ }
class Container extends Component {
someInstanceMethod() {
- return someData;
+ return someData
}
render() {
- return ;
+ return
}
}
- const decorator = connect(state => state, null, null, { withRef: true });
- const Decorated = decorator(Container);
+ const decorator = connect(state => state, null, null, { withRef: true })
+ const Decorated = decorator(Container)
const tree = TestUtils.renderIntoDocument(
- );
+ )
- const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated);
+ const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated)
- expect(() => decorated.someInstanceMethod()).toThrow();
- expect(decorated.getWrappedInstance().someInstanceMethod()).toBe(someData);
- expect(decorated.refs.wrappedInstance.someInstanceMethod()).toBe(someData);
- });
+ expect(() => decorated.someInstanceMethod()).toThrow()
+ expect(decorated.getWrappedInstance().someInstanceMethod()).toBe(someData)
+ expect(decorated.refs.wrappedInstance.someInstanceMethod()).toBe(someData)
+ })
it('should wrap impure components without supressing updates', () => {
- const store = createStore(() => ({}));
+ const store = createStore(() => ({}))
class ImpureComponent extends Component {
static contextTypes = {
statefulValue: React.PropTypes.number
- };
+ }
render() {
- return ;
+ return
}
}
- const decorator = connect(state => state, null, null, { pure: false });
- const Decorated = decorator(ImpureComponent);
+ const decorator = connect(state => state, null, null, { pure: false })
+ const Decorated = decorator(ImpureComponent)
class StatefulWrapper extends Component {
state = {
value: 0
- };
+ }
static childContextTypes = {
statefulValue: React.PropTypes.number
- };
+ }
getChildContext() {
return {
statefulValue: this.state.value
- };
+ }
}
render() {
- return ;
- };
+ return
+ }
}
const tree = TestUtils.renderIntoDocument(
- );
+ )
- const target = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- const wrapper = TestUtils.findRenderedComponentWithType(tree, StatefulWrapper);
- expect(target.props.statefulValue).toEqual(0);
- wrapper.setState({ value: 1 });
- expect(target.props.statefulValue).toEqual(1);
- });
+ const target = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ const wrapper = TestUtils.findRenderedComponentWithType(tree, StatefulWrapper)
+ expect(target.props.statefulValue).toEqual(0)
+ wrapper.setState({ value: 1 })
+ expect(target.props.statefulValue).toEqual(1)
+ })
it('calls mapState and mapDispatch for impure components', () => {
const store = createStore(() => ({
foo: 'foo',
bar: 'bar'
- }));
+ }))
- const mapStateSpy = expect.createSpy();
- const mapDispatchSpy = expect.createSpy().andReturn({});
+ const mapStateSpy = expect.createSpy()
+ const mapDispatchSpy = expect.createSpy().andReturn({})
class ImpureComponent extends Component {
render() {
- return ;
+ return
}
}
const decorator = connect(
- (state, {storeGetter}) => {
- mapStateSpy();
- return {value: state[storeGetter.storeKey]};
+ (state, { storeGetter }) => {
+ mapStateSpy()
+ return { value: state[storeGetter.storeKey] }
},
mapDispatchSpy,
null,
{ pure: false }
- );
- const Decorated = decorator(ImpureComponent);
+ )
+ const Decorated = decorator(ImpureComponent)
class StatefulWrapper extends Component {
state = {
- storeGetter: {storeKey: 'foo'}
- };
+ storeGetter: { storeKey: 'foo' }
+ }
render() {
- return ;
- };
+ return
+ }
}
const tree = TestUtils.renderIntoDocument(
- );
+ )
- const target = TestUtils.findRenderedComponentWithType(tree, Passthrough);
- const wrapper = TestUtils.findRenderedComponentWithType(tree, StatefulWrapper);
+ const target = TestUtils.findRenderedComponentWithType(tree, Passthrough)
+ const wrapper = TestUtils.findRenderedComponentWithType(tree, StatefulWrapper)
- expect(mapStateSpy.calls.length).toBe(2);
- expect(mapDispatchSpy.calls.length).toBe(2);
- expect(target.props.statefulValue).toEqual('foo');
+ expect(mapStateSpy.calls.length).toBe(2)
+ expect(mapDispatchSpy.calls.length).toBe(2)
+ expect(target.props.statefulValue).toEqual('foo')
// Impure update
- const storeGetter = wrapper.state.storeGetter;
- storeGetter.storeKey = 'bar';
- wrapper.setState({ storeGetter });
+ const storeGetter = wrapper.state.storeGetter
+ storeGetter.storeKey = 'bar'
+ wrapper.setState({ storeGetter })
- expect(mapStateSpy.calls.length).toBe(3);
- expect(mapDispatchSpy.calls.length).toBe(3);
- expect(target.props.statefulValue).toEqual('bar');
- });
+ expect(mapStateSpy.calls.length).toBe(3)
+ expect(mapDispatchSpy.calls.length).toBe(3)
+ expect(target.props.statefulValue).toEqual('bar')
+ })
it('should pass state consistently to mapState', () => {
- const store = createStore(stringBuilder);
+ const store = createStore(stringBuilder)
- store.dispatch({ type: 'APPEND', body: 'a'});
- let childMapStateInvokes = 0;
+ store.dispatch({ type: 'APPEND', body: 'a' })
+ let childMapStateInvokes = 0
@connect(state => ({ state }), null, null, { withRef: true })
class Container extends Component {
emitChange() {
- store.dispatch({ type: 'APPEND', body: 'b'});
+ store.dispatch({ type: 'APPEND', body: 'b' })
}
render() {
@@ -1291,19 +1291,19 @@ describe('React', () => {
- );
+ )
}
}
@connect((state, parentProps) => {
- childMapStateInvokes++;
+ childMapStateInvokes++
// The state from parent props should always be consistent with the current state
- expect(state).toEqual(parentProps.parentState);
- return {};
+ expect(state).toEqual(parentProps.parentState)
+ return {}
})
class ChildContainer extends Component {
render() {
- return ;
+ return
}
}
@@ -1311,21 +1311,21 @@ describe('React', () => {
- );
+ )
- expect(childMapStateInvokes).toBe(2);
+ expect(childMapStateInvokes).toBe(2)
// The store state stays consistent when setState calls are batched
ReactDOM.unstable_batchedUpdates(() => {
- store.dispatch({ type: 'APPEND', body: 'c'});
- });
- expect(childMapStateInvokes).toBe(3);
+ store.dispatch({ type: 'APPEND', body: 'c' })
+ })
+ expect(childMapStateInvokes).toBe(3)
// setState calls DOM handlers are batched
- const container = TestUtils.findRenderedComponentWithType(tree, Container);
- const node = container.getWrappedInstance().refs.button;
- TestUtils.Simulate.click(node);
- expect(childMapStateInvokes).toBe(4);
+ const container = TestUtils.findRenderedComponentWithType(tree, Container)
+ const node = container.getWrappedInstance().refs.button
+ TestUtils.Simulate.click(node)
+ expect(childMapStateInvokes).toBe(4)
// In future all setState calls will be batched[1]. Uncomment when it
// happens. For now redux-batched-updates middleware can be used as
@@ -1333,23 +1333,23 @@ describe('React', () => {
//
// [1]: https://twitter.com/sebmarkbage/status/642366976824864768
//
- // store.dispatch({ type: 'APPEND', body: 'd'});
- // expect(childMapStateInvokes).toBe(5);
- });
+ // store.dispatch({ type: 'APPEND', body: 'd' })
+ // expect(childMapStateInvokes).toBe(5)
+ })
it('should not render the wrapped component when mapState does not produce change', () => {
- const store = createStore(stringBuilder);
- let renderCalls = 0;
- let mapStateCalls = 0;
+ const store = createStore(stringBuilder)
+ let renderCalls = 0
+ let mapStateCalls = 0
@connect(() => {
- mapStateCalls++;
- return {}; // no change!
+ mapStateCalls++
+ return {} // no change!
})
class Container extends Component {
render() {
- renderCalls++;
- return ;
+ renderCalls++
+ return
}
}
@@ -1357,17 +1357,17 @@ describe('React', () => {
- );
+ )
- expect(renderCalls).toBe(1);
- expect(mapStateCalls).toBe(2);
+ expect(renderCalls).toBe(1)
+ expect(mapStateCalls).toBe(2)
- store.dispatch({ type: 'APPEND', body: 'a'});
+ store.dispatch({ type: 'APPEND', body: 'a' })
// After store a change mapState has been called
- expect(mapStateCalls).toBe(3);
+ expect(mapStateCalls).toBe(3)
// But render is not because it did not make any actual changes
- expect(renderCalls).toBe(1);
- });
- });
-});
+ expect(renderCalls).toBe(1)
+ })
+ })
+})
diff --git a/test/setup.js b/test/setup.js
index b4e5ab07b..c2e0f0cab 100644
--- a/test/setup.js
+++ b/test/setup.js
@@ -1,5 +1,5 @@
-import { jsdom } from 'jsdom';
+import { jsdom } from 'jsdom'
-global.document = jsdom('');
-global.window = document.defaultView;
-global.navigator = global.window.navigator;
+global.document = jsdom('')
+global.window = document.defaultView
+global.navigator = global.window.navigator
diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js
index 13cd49a1c..4c880dc40 100644
--- a/test/utils/isPlainObject.spec.js
+++ b/test/utils/isPlainObject.spec.js
@@ -1,19 +1,19 @@
-import expect from 'expect';
-import isPlainObject from '../../src/utils/isPlainObject';
+import expect from 'expect'
+import isPlainObject from '../../src/utils/isPlainObject'
describe('Utils', () => {
describe('isPlainObject', () => {
it('should return true only if plain object', () => {
function Test() {
- this.prop = 1;
+ this.prop = 1
}
- expect(isPlainObject(new Test())).toBe(false);
- expect(isPlainObject(new Date())).toBe(false);
- expect(isPlainObject([1, 2, 3])).toBe(false);
- expect(isPlainObject(null)).toBe(false);
- expect(isPlainObject()).toBe(false);
- expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true);
- });
- });
-});
+ expect(isPlainObject(new Test())).toBe(false)
+ expect(isPlainObject(new Date())).toBe(false)
+ expect(isPlainObject([ 1, 2, 3 ])).toBe(false)
+ expect(isPlainObject(null)).toBe(false)
+ expect(isPlainObject()).toBe(false)
+ expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true)
+ })
+ })
+})
diff --git a/test/utils/shallowEqual.spec.js b/test/utils/shallowEqual.spec.js
index ef98c5b09..662ceedd2 100644
--- a/test/utils/shallowEqual.spec.js
+++ b/test/utils/shallowEqual.spec.js
@@ -1,5 +1,5 @@
-import expect from 'expect';
-import shallowEqual from '../../src/utils/shallowEqual';
+import expect from 'expect'
+import shallowEqual from '../../src/utils/shallowEqual'
describe('Utils', () => {
describe('shallowEqual', () => {
@@ -9,23 +9,23 @@ describe('Utils', () => {
{ a: 1, b: 2, c: undefined },
{ a: 1, b: 2, c: undefined }
)
- ).toBe(true);
+ ).toBe(true)
expect(
shallowEqual(
{ a: 1, b: 2, c: 3 },
{ a: 1, b: 2, c: 3 }
)
- ).toBe(true);
+ ).toBe(true)
- const o = {};
+ const o = {}
expect(
shallowEqual(
{ a: 1, b: 2, c: o },
{ a: 1, b: 2, c: o }
)
- ).toBe(true);
- });
+ ).toBe(true)
+ })
it('should return false if first argument has too many keys', () => {
expect(
@@ -33,8 +33,8 @@ describe('Utils', () => {
{ a: 1, b: 2, c: 3 },
{ a: 1, b: 2 }
)
- ).toBe(false);
- });
+ ).toBe(false)
+ })
it('should return false if second argument has too many keys', () => {
expect(
@@ -42,8 +42,8 @@ describe('Utils', () => {
{ a: 1, b: 2 },
{ a: 1, b: 2, c: 3 }
)
- ).toBe(false);
- });
+ ).toBe(false)
+ })
it('should return false if arguments have different keys', () => {
expect(
@@ -51,7 +51,7 @@ describe('Utils', () => {
{ a: 1, b: 2, c: undefined },
{ a: 1, bb: 2, c: undefined }
)
- ).toBe(false);
- });
- });
-});
+ ).toBe(false)
+ })
+ })
+})
diff --git a/test/utils/wrapActionCreators.js b/test/utils/wrapActionCreators.js
index af31ce4d6..3cbb02c0d 100644
--- a/test/utils/wrapActionCreators.js
+++ b/test/utils/wrapActionCreators.js
@@ -1,5 +1,5 @@
-import expect from 'expect';
-import wrapActionCreators from '../../src/utils/wrapActionCreators';
+import expect from 'expect'
+import wrapActionCreators from '../../src/utils/wrapActionCreators'
describe('Utils', () => {
describe('wrapActionCreators', () => {
@@ -8,24 +8,24 @@ describe('Utils', () => {
function dispatch(action) {
return {
dispatched: action
- };
+ }
}
- const actionResult = {an: 'action'};
+ const actionResult = { an: 'action' }
const actionCreators = {
action: () => actionResult
- };
+ }
- const wrapped = wrapActionCreators(actionCreators);
- expect(wrapped).toBeA(Function);
- expect(() => wrapped(dispatch)).toNotThrow();
- expect(() => wrapped().action()).toThrow();
+ const wrapped = wrapActionCreators(actionCreators)
+ expect(wrapped).toBeA(Function)
+ expect(() => wrapped(dispatch)).toNotThrow()
+ expect(() => wrapped().action()).toThrow()
- const bound = wrapped(dispatch);
- expect(bound.action).toNotThrow();
- expect(bound.action().dispatched).toBe(actionResult);
+ const bound = wrapped(dispatch)
+ expect(bound.action).toNotThrow()
+ expect(bound.action().dispatched).toBe(actionResult)
- });
- });
-});
+ })
+ })
+})
diff --git a/webpack.config.base.js b/webpack.config.base.js
index a7130d0b0..1a063842c 100644
--- a/webpack.config.base.js
+++ b/webpack.config.base.js
@@ -1,20 +1,20 @@
-'use strict';
+'use strict'
-var webpack = require('webpack');
+var webpack = require('webpack')
var reactExternal = {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
-};
+}
var reduxExternal = {
root: 'Redux',
commonjs2: 'redux',
commonjs: 'redux',
amd: 'redux'
-};
+}
module.exports = {
externals: {
@@ -33,4 +33,4 @@ module.exports = {
resolve: {
extensions: ['', '.js']
}
-};
+}
diff --git a/webpack.config.development.js b/webpack.config.development.js
index e509d7cd2..7a974f743 100644
--- a/webpack.config.development.js
+++ b/webpack.config.development.js
@@ -1,14 +1,14 @@
-'use strict';
+'use strict'
-var webpack = require('webpack');
-var baseConfig = require('./webpack.config.base');
+var webpack = require('webpack')
+var baseConfig = require('./webpack.config.base')
-var config = Object.create(baseConfig);
+var config = Object.create(baseConfig)
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
-];
+]
-module.exports = config;
+module.exports = config
diff --git a/webpack.config.production.js b/webpack.config.production.js
index f4589cc06..98732276f 100644
--- a/webpack.config.production.js
+++ b/webpack.config.production.js
@@ -1,9 +1,9 @@
-'use strict';
+'use strict'
-var webpack = require('webpack');
-var baseConfig = require('./webpack.config.base');
+var webpack = require('webpack')
+var baseConfig = require('./webpack.config.base')
-var config = Object.create(baseConfig);
+var config = Object.create(baseConfig)
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
@@ -15,6 +15,6 @@ config.plugins = [
warnings: false
}
})
-];
+]
-module.exports = config;
+module.exports = config