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

[Core] Removes mergeAndPrefix(), refactor uses mergeStyles() and prepareStyles() #2886

Merged
merged 1 commit into from
Jan 12, 2016

Conversation

newoga
Copy link
Contributor

@newoga newoga commented Jan 11, 2016

This commit removes all instances of mergeAndPrefix. It also aims to use mergeStyles and prepareStyles in a more consistent manner. All uses of mergeAndPrefix were switched to mergeStyles OR prepareStyles depending on the following condition:

  • If the computed style being is passed directly to a html tag's style attribute (ie. div, span, li, etc.) OR an externally managed component's style prop (such as ReactTransitionGroup), use prepareStyles
  • If the computed style being passed to an internal component's style prop, or any related style props, use mergeStyles

This prevents any top level/parent components from prematurely preparing styles (styles should only be prepared when attaching to a DOM node).

I did searches across src and found places where that pattern were not followed and switched them as well.

@newoga
Copy link
Contributor Author

newoga commented Jan 11, 2016

@alitaheri @oliviertassinari Please take your time on this one and review/test very carefully. I want to start refactoring styleUtils so that we can work on removing the style-propable mixin. I also want to see if there are any performance optimizations (like memoization) with our use of the merge and prepare functions.

I think removing mergeAndPrefix is the first step.

Related to #2852

@oliviertassinari
Copy link
Member

@newoga I will review it. That's a very good first step 👍.

@newoga
Copy link
Contributor Author

newoga commented Jan 12, 2016

@oliviertassinari @alitaheri What are your thoughts on switching prepareStyles to not optionally accept an array of styles that can be merged. To me this is kind of confusing and abuses single responsibility principle a little bit.

I think it's more explicit to use merge only when you want to merge styles together, then use prepare when you want to take a merged result and perform "final" framework related modifications to it like auto prefixing or direction changing. Therefore, the method signatures would look like this:

function merge(...args) {
  // impl
}

function prepare(muiTheme, style) {
  // impl
}

// If you want to merge themes while preparing, do:
prepare(muiTheme, merge(styleA, styleB));

We don't have to do in in this PR, but wanted to get your feedback on it either way.

@alitaheri
Copy link
Member

@newoga Good work 👍 Thank you ^_^

We don't have to do in in this PR, but wanted to get your feedback on it either way.

I like this idea very much! Yeah I think this is how it should be.


let children = React.Children.map(this.props.children, (child) => {
return React.cloneElement(child, {style: this.prepareStyles(styles.mediaChild, child.props.style)});
return React.cloneElement(child, {style: this.mergeStyles(styles.mediaChild, child.props.style)});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CardMedia doesn't seem to take Material Ui component. Shouldn't we use prepareStyles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think you're right, my mistake!

Thanks for catching. 😄

@oliviertassinari
Copy link
Member

@newoga Nice work, I have checked every components of the docs, looking for You're calling ensureDirection() on the same style object twice. (occurs when prepareStyles is called twice).
I couldn't find one 👍.

@newoga
Copy link
Contributor Author

newoga commented Jan 12, 2016

@oliviertassinari @alitaheri Thanks much for your review!

This is just the first step, if everything looks good with just the overall removal of mergeAndPrefix and some of the general cleanup of mergeStyles and prepareStyles, I say we can merge and I'll get a new PR with a utils/style.js refactor in short order 😄

I'm going to squash the couple of small merge and prepare fixes that we found now.

@alitaheri
Copy link
Member

@newoga Thank you. This is certainly a great step toward better code quality 👍 👍 👍

…tyles()

This commit removes all instances of `mergeAndPrefix()` in our internal codebase. It also deprecates use of the `mergeAndPrefix()` method from the `style-propable` mixin. It also changes our use of `mergeStyles()` and `prepareStyles()` accross src in a more consistent manner. All uses of `mergeAndPrefix()` were switched to `mergeStyles()` OR `prepareStyles()` based on the following condition:

- If the computed style is passed directly to a html tag's style attribute (ie. div, span, li, etc.) OR to an externally managed component's style prop (such as `ReactTransitionGroup`), use `prepareStyles()`
- If the computed style is passed to an internal component's style prop, or any related style props, use `mergeStyles()`

This prevents any top level/parent components from prematurely preparing styles (styles should only be prepared when attaching to a DOM node).

I did searches accross src and found places where that pattern were not followed and switched them as well.
@newoga
Copy link
Contributor Author

newoga commented Jan 12, 2016

@alitaheri No problem, slowly but surely we will get there! 😄

@alitaheri @oliviertassinari
I squashed the commits and reset style-propable.js back to what it was originally but added a deprecation warning to the mergeAndPrefix() method. If all is good, feel free to merge!

@alitaheri
Copy link
Member

👍 👍 Thank you @newoga

alitaheri added a commit that referenced this pull request Jan 12, 2016
[Core] Removes mergeAndPrefix(), refactor uses mergeStyles() and prepareStyles()
@alitaheri alitaheri merged commit 2beb4a5 into mui:master Jan 12, 2016
@newoga newoga deleted the mergeAndPrefix-removal branch January 12, 2016 20:05
@zannager zannager added the core Infrastructure work going on behind the scenes label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants