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

[Icon Builder] Add muiName to generated SvgIcons #4188

Merged
merged 2 commits into from
May 8, 2016
Merged

[Icon Builder] Add muiName to generated SvgIcons #4188

merged 2 commits into from
May 8, 2016

Conversation

mbrookes
Copy link
Member

@mbrookes mbrookes commented May 6, 2016

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

Adding muiName necessitated switching to class syntax to support shouldComponentUpdate

Edit: Removed pure() from the template, and added shouldComponentUpdate to SvgIcon.

After some discussion, just added muiName to the existing template, and updated the build script comments and package.json script.

@@ -47,6 +47,7 @@
"lodash.merge": "^4.3.5",
"lodash.throttle": "^4.0.1",
"react-addons-create-fragment": "^15.0.1",
"react-addons-shallow-compare": "^15.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Member

Choose a reason for hiding this comment

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

We already have it in our utils folder don't we?

Copy link
Member

@nathanmarks nathanmarks May 7, 2016

Choose a reason for hiding this comment

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

@oliviertassinari We are currently using it from recompose: https://github.com/callemall/material-ui/blob/master/src/TextField/TextField.js#L4

But I think we should get rid of recompose.... all we are using it for is pure() which is an entire component instance just to wrap a component with:

class Pure extends Component {

  shouldComponentUpdate(nextProps) {
    return !shallowEqual(this.props, nextProps);
  }

  render() {}
}

Which should be done normally, it is very little code

Copy link
Member Author

@mbrookes mbrookes May 7, 2016

Choose a reason for hiding this comment

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

@oliviertassinari It isn't needed - I had used that first, then removed it from the template, but not from package,json. Done now.

Copy link
Member Author

@mbrookes mbrookes May 7, 2016

Choose a reason for hiding this comment

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

@nathanmarks - the only component left using pure() is Stepper! 😆

@oliviertassinari
Copy link
Member

Could you give us some context on the use case. In which situation do we need the muiName to be present?

@mbrookes
Copy link
Member Author

mbrookes commented May 7, 2016

The same as any other component that we need to tell it's type, but specifically for Button. 🎉

@oliviertassinari
Copy link
Member

oliviertassinari commented May 7, 2016

Adding muiName necessitated switching to class syntax to support shouldComponentUpdate

I'm having some doubt about this statement. Why can't we add muiName to the prototype of the function, like for the defaultProps or the propTypes?

@mbrookes
Copy link
Member Author

mbrookes commented May 7, 2016

I'm having some doubt about this statement.

Yeah, you're right it was late, I misremembered the code refactor dependancy order. I switched to class to nix pure(), which @nathanmarks pointed out wraps the component in a component, just to add shouldComponentUpdate.

However if we add shouldComponentUpdate to SvgIcon instead, then we shouldn't need it in the svg-icons right? (I know it's better to have it as high up the render tree as possible, but since the svg-icons don't do anything it shouldn't matter if I understand correctly).

And if it's possible to add muiName to an FSC, then we don't need to switch to a class.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 7, 2016

which @nathanmarks pointed out wraps the component in a component, just to add shouldComponentUpdate.

Isn't the purpose of composition? I don't see the win with this change of pure implementation.
The pure HOC do no create a new component as our icons are referentially transparents.
Switching to classes will increase the build size by 300 % (after transpilation, well I should check the number, it's what I remember from trying the two alternatives).
For the history of this change: #3326.

@mbrookes
Copy link
Member Author

mbrookes commented May 7, 2016

Switching to classes will increase the build size by 300 % (after transpilation).

But they aren't classes. :)

f71b5c9

pure() is replaced by shouldComponentUpdate() in SvgIcon.

@@ -56,6 +57,10 @@ class SvgIcon extends Component {
hovered: false,
};

shouldComponentUpdate = (nextProps, nextState) => {
Copy link
Member

@oliviertassinari oliviertassinari May 7, 2016

Choose a reason for hiding this comment

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

I don't think that we should implement a shouldComponentUpdate for any component that accepts a children property. The check will almost always fail unless users are caching their children manually or with babel-plugin-transform-react-constant-elements.

Copy link
Member

@oliviertassinari oliviertassinari May 7, 2016

Choose a reason for hiding this comment

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

Or we could tell users to use this babel plugin in production and to parse material-ui and we should be good 😁.

@nathanmarks
Copy link
Member

nathanmarks commented May 8, 2016

@oliviertassinari thanks for highlighting the main feature I overlooked in this use case.

@0-vortex
Copy link

0-vortex commented May 8, 2016

I thought I saw you change 'material-ui/lib/svg-icon' to 'material-ui/SvgIcon' in this PR. Generating icons with --mui-require absolute results in

var _SvgIcon = require('material-ui/lib/SvgIcon');

var _SvgIcon2 = _interopRequireDefault(_SvgIcon);

Is this a typo or did I miss the documentation changes to icon-builder ?

@oliviertassinari
Copy link
Member

@vrtxf That's an old issue. The path should be material-ui/SvgIcon. Good catch.
Do you want to submit a PR?

@0-vortex
Copy link

0-vortex commented May 8, 2016

sure

@mbrookes mbrookes deleted the icon-builder-add-muiname branch September 11, 2018 22:00
@zannager zannager added the component: SvgIcon The React component. label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: SvgIcon The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants