Skip to content

Allow this.getState references (not calls) in lifecycle methods. #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2015

Conversation

benmosher
Copy link
Contributor

I think this should not be considered an error/warning by this rule: (my actual code follows)

componentDidMount() {
    this.handleStoreEvent = _.compose(this.setState, getStoreState).bind(this);
    dependencies.add(this.handleStoreEvent);
},

While I don't know that this is great code per se, it is essentially binding setState to a list of Flux stores via a helper (dependencies). This seems to me like a valid use of setState within componentDidMount.

I refactored both rules pertaining to setState to respond to CallExpression nodes instead of MemberExpression, and it returns if the callee is not a MemberExpression. The original logic follows thereafter.

I can imagine also potentially making this reduction in strength an option, but I believe the behavior here captures the spirit of the rule, and thus an option should not be necessary.

Submitted for your consideration. 👍

… this.setState; references/assignment are allowed.

Extra credit: ensure the reference is not used to be called thereafter. (not part of this commit.)
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.57%) to 98.43% when pulling 9e670c7 on benmosher:master into d79eadc on yannickcr:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e42ba31 on benmosher:master into d79eadc on yannickcr:master.

@yannickcr
Copy link
Member

Looks good to me

And I think this is the way this rule should work, so an option is not necessary.

Thanks for your contribution :)

@yannickcr yannickcr merged commit 0c24de4 into jsx-eslint:master Mar 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants