-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
Improve Immutability #4
Comments
Not directly related to immutability, but a popular way to improve performance / UX of React applications is to optimize rendering using the You could also consider similarly optimizing your "helper" components ( I also notice React has introduced a EDIT: thinking about it more, actually this concern could be largely obviated by the user just including |
That's a great start for sure. I've never used PurComponent's either, and judging by the reliance on the deeper data structures, it might produce some false negatives if we did use it. I know this is one of the tipping points that redux-form had where they were supplying many props (much like react-form does) to the child component that renders the form. Because of this pattern, the child component had to update even if only one field in the values object changed. I imagine this is why they moved to a 100% opt-in value subscription and field wrapper mentality. It might be challenging to find the middle ground, but right now I feel that the easy access to the state values via props is more valuable in comparison to the edge case performance benefits that a value subscription pattern gives. What do you think? |
I think you are right, it's probably not worth it at this point. The What might be cool though to try is taking some hard measurements, and then you can see how performance changes as the wrapped component varies in complexity, and also sanity-check that future enhancements to your code don't tank performance. You could utilize benchmark.js, enzyme, and jsdom to create a suite of tests in which the React components mount to a virtual DOM. I haven't actually ever set this up successfully but I imagine someone has. I might try playing with it later on. |
One compromise I am imagining is possibly putting all of the formstate props behind their own subscriber components permanently. It would be similar in spirit to redux-form's approach, but instead of needing to write lengthy selectors, you would be referencing values much closer to home. imagine: Form()(({values}) => {
return (
<form>
<FormInput field='something'/>
{values.friends.map((friends, i) => (
<div key={i}>
<Text
field={['friends', i, 'name']}
placeholder='Friend Name'
/>
</div>
))}
</form>
)
})
// becomes
Form()(() => {
return (
<form>
<FormInput field='something'/>
<FormValue field='friends'>
{(friends) => (
friends.map((friends, i) => (
<div key={i}>
<Text
field={['friends', i, 'name']}
placeholder='Friend Name'
/>
</div>
))
})}
</FormValue>
</form>
)
}) |
That would allow the main form component to be treated as pure, unless it's own props change :) |
I'm trying to find any other props the form passes down that would need to be placed behind a subscriber component if we took this approach... |
This might take some more thinking and discover as the library matures. For now, everything works and performance is on par with what is expected from React. Closing until it becomes a real issue. |
Aside from everything functioning great, performance and component lifecycle could be slightly improved by enforcing immutability throughout a few places. I'm open to ideas.
The text was updated successfully, but these errors were encountered: