diff --git a/src/components/connect.js b/src/components/connect.js index 5b31632d1..3e01744f1 100644 --- a/src/components/connect.js +++ b/src/components/connect.js @@ -28,8 +28,8 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, wrapActionCreators(mapDispatchToProps) : mapDispatchToProps || defaultMapDispatchToProps const finalMergeProps = mergeProps || defaultMergeProps - const shouldUpdateStateProps = finalMapStateToProps.length > 1 - const shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1 + const shouldUpdateStateProps = finalMapStateToProps.length !== 1 + const shouldUpdateDispatchProps = finalMapDispatchToProps.length !== 1 const { pure = true, withRef = false } = options // Helps track hot reloading. diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 118b04603..893fec348 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -426,10 +426,12 @@ describe('React', () => { let invocationCount = 0 - @connect(() => { + /*eslint-disable no-unused-vars */ + @connect((arg1) => { invocationCount++ return {} }) + /*eslint-enable no-unused-vars */ class WithoutProps extends Component { render() { return @@ -467,6 +469,53 @@ describe('React', () => { expect(invocationCount).toEqual(2) }) + it('should invoke mapState every time props are changed if it has zero arguments', () => { + const store = createStore(stringBuilder) + + let invocationCount = 0 + + @connect(() => { + invocationCount++ + return {} + }) + + class WithoutProps extends Component { + render() { + return + } + } + + class OuterComponent extends Component { + constructor() { + super() + this.state = { foo: 'FOO' } + } + + setFoo(foo) { + this.setState({ foo }) + } + + render() { + return ( +
+ +
+ ) + } + } + + let outerComponent + TestUtils.renderIntoDocument( + + outerComponent = c} /> + + ) + outerComponent.setFoo('BAR') + outerComponent.setFoo('DID') + + expect(invocationCount).toEqual(4) + }) + it('should invoke mapState every time props are changed if it has a second argument', () => { const store = createStore(stringBuilder) @@ -524,10 +573,12 @@ describe('React', () => { let invocationCount = 0 - @connect(null, () => { + /*eslint-disable no-unused-vars */ + @connect(null, (arg1) => { invocationCount++ return {} }) + /*eslint-enable no-unused-vars */ class WithoutProps extends Component { render() { return @@ -566,6 +617,54 @@ describe('React', () => { expect(invocationCount).toEqual(1) }) + it('should invoke mapDispatch every time props are changed if it has zero arguments', () => { + const store = createStore(stringBuilder) + + let invocationCount = 0 + + @connect(null, () => { + invocationCount++ + return {} + }) + + class WithoutProps extends Component { + render() { + return + } + } + + class OuterComponent extends Component { + constructor() { + super() + this.state = { foo: 'FOO' } + } + + setFoo(foo) { + this.setState({ foo }) + } + + render() { + return ( +
+ +
+ ) + } + } + + let outerComponent + TestUtils.renderIntoDocument( + + outerComponent = c} /> + + ) + + outerComponent.setFoo('BAR') + outerComponent.setFoo('DID') + + expect(invocationCount).toEqual(3) + }) + it('should invoke mapDispatch every time props are changed if it has a second argument', () => { const store = createStore(stringBuilder)