-
Notifications
You must be signed in to change notification settings - Fork 141
componentWillReceiveProps optimisation #94
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
Conversation
src/components/connect.js
Outdated
|
|
||
| componentWillReceiveProps(nextProps, nextContext) { | ||
| if (defaults.pure) { | ||
| this._propsAndContextDidntChange = shallowEqual(this.props, nextProps) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if anyone can think of a better name for this._propsAndContextDidntChange I'm all ears :)
(I save it to avoid recomputing it shouldComponentUpdate (which, if props or context changed, always runs after componentWillReceiveProps))
|
I think I'm going back on this and I think this optimisation should apply only to
What do you think @ryanbrainard ? |
8a95260 to
48d5ac4
Compare
I'm not sure I 100% agree (mostly because I haven't thought about it enough), but I think that confining it to |
|
I'm not sure myself, because for my uses I always want the component to be pure, but some use cases might require that it be non pure, so it'd probably have to be an option and I don't like options... |
|
I've rebased |
|
Released in v1.0.0-beta.2. Thanks @nfcampos ! Note, when I was testing this out, my app was still using React Router 1.0, so the router stuff was in |
|
Good points. This got me thinking about times when The optimisation in this PR takes care of (a) and (c). (b) would actually be good to take care as well, I don't think there's any sane use case in which As for subtle bugs, basically they'll come down to times when people write Directly doing something like onlyUpdateForKeys(['this', 'that'])(connect( props => ... )(SomeComponent))sounds perfectly reasonable but I think the cases above make this more primitive optimisation worth it, what do you think? |
|
Interesting point about
If we did something like this, are you thinking something that would go into Side note: This does make me question again a bit of we should be stuffing |
|
|
Agree on all points. You're right, I also agree on a chainable |
|
I've opened a PR with the |
|
@ryanbrainard any opinion on the above, whether to use a dependency for that or not? |
|
@nfcampos i was hesitant to pull in more deps, but that is probably better to use something like |
|
@ryanbrainard sadly lodash doesn't have a |
|
@nfcampos Sure, have at it :) |
todo:
mapPropsToRequestsToPropsisn't called if neither props nor context actually changedmapPropsToRequestsToPropsbeing called if either props or context actually changed (they already do)