-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Toolbar] Remove style-propable mixin #3180
Conversation
@newoga I think that it's an excellent idea! |
I'm glad, I think this change would make me very happy. 😆 |
Pure awesomeness and conciseness 👍 👍 This will bring us very close to memoization 😍 |
Let's do it! 😄 🎉 I applied that pattern to the rest of the components under |
}, | ||
|
||
getTheme() { | ||
return this.state.muiTheme.toolbar; | ||
_handleMouseEnterFontIcon: (style) => (e) => { |
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 want to draw your attention here for feed back.
The previous implementation was recomputed the whole style object for each property on mouse enter and leave:
_handleMouseEnterFontIcon(e) {
e.target.style.zIndex = this.getStyles().icon.hover.zIndex;
e.target.style.color = this.getStyles().icon.hover.color;
},
I replaced it with a higher order function so that the style object is only computed once per render. Honestly, if I had my way, we would move these outside of the class too! 😁
If these were removed, the only time this.
is called is for these three scenarios:
this.props
this.setState({muiTheme: aMuiTheme})
this.state.muiTheme
It's so close to being purely functional!
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.
Yeah! That would be great. But it's going to need a lot of thought. I think an HOC that can handle these interactions would make this stateless (an a whole lot of other components) but I don't know how that is possible.
Signed-off-by: Neil Gabbadon <[email protected]>
Done, change |
@@ -197,7 +196,7 @@ const ToolbarGroup = React.createClass({ | |||
}, this); | |||
|
|||
return ( | |||
<div {...other} className={className} style={this.prepareStyles(styles.root, style)}> | |||
<div {...other} className={className} style={prepareStyles(Object.assign({}, styles.root, style))}> |
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 see you're doing this almost everywhere you use prepareStyles
maybe it's time to move the logic before we merge these? @oliviertassinari What do you think?
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 don't follow. What would be the advantage?
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.
well since it's gonna show up everywhere, why not just put it in the prepareStyles
function in the first place. this way we won't have to make the assumption that the styles passed down to prepareStyles
are safe to mutate. we'll just make them safe ourselves.
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.
That's fair. I see a performance concern in this approach. 50%+ of the time, the parameter passed to the prepareStyles
is safe to mutate. I feel like we will end up with more Object.assign({},
with your solution.
However, in this line I think that prepareStyles(Object.assign(styles.root, style))
would work just fine. But that's not 100% safe for future code changes (side effect).
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 think more than 50% would be safe, you're right. Let's go with this approach for now 👍
I'm all good. feel free to merge 👍 |
[Toolbar] Remove style-propable mixin
@oliviertassinari @alitaheri @mbrookes
This isn't done, as I'm migrating the code, I wanted to get your feedback on this pattern of moving
getStyles()
outside of the class declaration (and changing the method signature togetStyles(props, state)
.I think this approach has the following benefits:
this.getTheme()
andthis.getSpacing()
props
andstate
(and ideally in the future just a function ofprops
)Final note: This PR was originally the start of migrating the toolbar components off of
style-propable
. After we decide, I'll rename the PR and finish that work.Signed-off-by: Neil Gabbadon [email protected]