-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Render components only after we have collected the Ion props #482
Conversation
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.
I really like the core idea for this, and it was actually just something that had run through my mind when I was thinking about it with Chirag last week. I think it's a good change that will make working with withIon
easier for engineers new to the codebase.
Took another crack at this one. |
Damn, it works so well in my initial testing ✨ Reviewing and testing some more. |
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.
This looks really great!
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.
Left one comment to get your thoughts. Rest looks awesome and works great. Am hype 🙂
// since keys that are configured to not init with stored values will | ||
// never appear on state when the component mounts - only after they update | ||
// organically. | ||
const requiredKeysForInit = _.chain(mapIonToState) |
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.
This logic is a bit confusing with .reduce and prev and curr. If i understand correctly we just want all keys except where initWithStoredValues is defined as false.
Then could this logic be used since it looks easier,
const requiredKeysForInit = _.chain(mapIonToState)
.omit(value => value.initWithStoredValues === false)
.keys()
.value();
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.
Nice tips @chiragsalian will update with that change! |
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.
LGTM
This PR is an attempt to solve the problem of all connected React components rendering without any initial data from the Ion. It achieves this without the addition of a memory cache and all other
Ion.connect()
usages and subscribers will remain untouched.As far as I can tell, there seem to be no performance impact here and there is not much difference between first getting this data from storage and loading it with a single call to render vs. mounting the component and then rendering many times as data is sent back to each connection.
The main change is that a component connected
withIon
will take the Ion props along with it for the first render. I think this is a really important change to make early on because:componentDidUpdate()
to replace prop handling logic done incomponentDidMount()
or theconstructor()
null
prop for any value then there is no key for that value. It won't first render withundefined
then appear to benull
so we can get more value out of things likepropTypes
and write less confusing code.cc @tgolen and cc @chiragsalian who just ran into an issue related to initial props being unknown
Curious to hear everyone's thoughts on this. This is my best attempt at staying respectful of the Ion philosophy while also keeping React best practices in mind.