Skip to content
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

[WIP] Call setState on React components once per dispatch #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iansinnott
Copy link

This PR is incomplete and open for discussion. I updated connect to only call setState on the wrapped component once per dispatch. I haven't yet touched nuclearMixin as I wanted to get feedback first and see if this is a change you would be interested in, but I'd be happy to update that as well.

This relates directly to optimizely/nuclear-js#195 and #13. Open to any feedback or suggestions.

I used this to simplify development by npm linking the local repo to my project
and having babel watch for changes.
…onents

Relates to optimizely/nuclear-js#195. For the connect
method, this change adds only one observer to the reactor per call as opposed
to adding a separate listener for each key returned by mapStateToProps.
I see let, var, const elsewhere in the project so I'm not if there is a
recommended way to declare variables. But I use const in my own code so I went
with that.
@iansinnott
Copy link
Author

Also relates to optimizely/nuclear-js#193

@jordangarcia
Copy link
Owner

Hmm, your approach seems reasonable, however we are trading evaluating all getters bound to a component vs only triggering getters that have changed and potentially calling re-render more than once.

So the question comes down to whether its more expensive to evaluate extraneous getters or call render multiple times, and I'm not quite convinced one is always better than the other.

It'd be nice to allow this to be configured somehow when using the decorator or have multiple decorators.

Thoughts?

@iansinnott
Copy link
Author

Very good point. My initial thought is that there is probably a better means of doing aggregation than creating a new getter that will be recomputed when any of the bound getters change.

I'm not yet sure what that would look like. For now i'm happy to simply use my own fork. In my codebase having aggregated state updates proved very helpful, especially with components that implement componentDidUpdate since intuitively it should only be called once with all changes applied.

I agree that the perf tradeoff is likely a deal breaker for some.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants