Skip to content

Commit

Permalink
fix length comparisons on xxxToProps functions
Browse files Browse the repository at this point in the history
Testing finalMap{State|Dispatch}ToProps.length > 1 breaks when these functions are wrapped in generic decorator functions. Instead, test for !== 1.
  • Loading branch information
planetcohen committed Nov 13, 2015
1 parent 8a096db commit 6c504b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@amanda-mitchell

amanda-mitchell Dec 23, 2015

This change causes shouldUpdateStateProps (which is called doStatePropsDependOnOwnProps) to be inappropriately set to true when finalMapStateToProps is equal to defaultMapStateToProps, which takes 0 arguments.

This comment has been minimized.

Copy link
@gaearon

gaearon Dec 24, 2015

Contributor

Very good catch, thanks. 04693ca

const shouldUpdateDispatchProps = finalMapDispatchToProps.length !== 1
const { pure = true, withRef = false } = options

// Helps track hot reloading.
Expand Down
8 changes: 6 additions & 2 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Passthrough {...this.props}/>
Expand Down Expand Up @@ -524,10 +526,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 <Passthrough {...this.props}/>
Expand Down

0 comments on commit 6c504b9

Please sign in to comment.