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

export emotion-theming from react-emotion #475

Closed
wants to merge 3 commits into from
Closed

export emotion-theming from react-emotion #475

wants to merge 3 commits into from

Conversation

quantizor
Copy link
Contributor

@quantizor quantizor commented Nov 27, 2017

While refactoring for a proof of concept, it quickly became cumbersome to have to split up the import just to pull in theming HOCs.

Since theming functionality is partially built-in by default in emotion v8 via supporting p => p.theme etc, I think it makes sense to go the rest of the way and re-export emotion-theming for ease of use.

The package itself should probably go away for emotion v9.

Checklist:

  • Documentation
  • Tests
  • Code complete

@quantizor
Copy link
Contributor Author

@tkh44 @mitchellhamilton hey folks, any comments on this?

@quantizor
Copy link
Contributor Author

From a somewhat selfish standpoint, this is a soft blocker on an internal migration away from styled-components at my company... trying to make the switch as painless as possible.

Out of curiosity, why the hesitation to merge this based on our previous twitter convo @tkh44?

@tkh44
Copy link
Member

tkh44 commented Dec 17, 2017

Sorry, I've been on vacation for the last few weeks.

@mitchellhamilton and I have talked about this about a week ago and we both were leaning on not merging. After some thought I think this might make sense just from a developer experience pov. Let's remove as much friction as possible for devs onboarding with emotion.

@mitchellhamilton when we talked you mentioned some concerns with the preact build. Can you elaborate here? What are the other cons?

@quantizor
Copy link
Contributor Author

After some thought I think this might make sense just from a developer experience pov

Very much agree. When I was refactoring it felt weird to consume theming from a separate package — like it was disconnected in some way. But that really isn’t the case since it relies on certain static variables being available, etc.

@emmatown
Copy link
Member

emotion-theming requires React.Children.only so it requires preact-compat whereas preact-emotion currently only requires preact so exporting emotion-theming from preact-emotion would mean it would require an alias from react to preact-compat.

I think what we could do is make emotion-theming export two functions, createWithTheme and createThemeProvider which accept a React-like API and a channel, they would return what their names imply. We would then export the created versions from react-emotion and preact-emotion. For the React.Children.only thing, we could check if Children exists and return props.children[0] if it doesn't exist.

@quantizor
Copy link
Contributor Author

quantizor commented Dec 17, 2017 via email

@@ -77,8 +77,18 @@ class ThemeProvider extends Component {
render() {
if (!this.props.children) {
return null
} else if (Array.isArray(this.props.children)) {
Copy link
Member

Choose a reason for hiding this comment

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

One trick I stole from preact-compat is to coerce it into an array.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Another option is to just not worry about it except for a warning. For React > 16 it wouldn't matter anyway, right?

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 for 16+ it wouldn’t matter.

I went ahead and updated the impl to be simpler :) along the lines of your suggestion

@quantizor
Copy link
Contributor Author

Any more notes?

@emmatown
Copy link
Member

In my comment before, I should have made it more clear that this would mean preact-emotion requires an alias from react to preact. While most preact apps have an alias from react to preact-compat, it would mean that preact wouldn't be a first class citizen in preact-emotion, this was why I was suggesting having factories. The other option would be to make emotion-theming a private module and bundle it in preact-emotion and react-emotion with react aliased to preact in the preact-emotion build. IMO factories make more sense because they'll fit with #464.

@quantizor
Copy link
Contributor Author

Gotcha. Okay I’ll work on this over the next few days 👍

@codecov
Copy link

codecov bot commented Dec 21, 2017

Codecov Report

Merging #475 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted Files Coverage Δ
packages/react-emotion/src/index.js 100% <ø> (ø) ⬆️
packages/emotion-theming/src/theme-provider.js 100% <100%> (ø) ⬆️
packages/emotion-theming/src/with-theme.js 100% <100%> (ø) ⬆️
packages/emotion-theming/src/index.js 100% <100%> (ø)
packages/emotion-theming/src/factory.js 100% <100%> (ø)

evan-scott-zocdoc and others added 2 commits December 22, 2017 00:43
While refactoring for a proof of concept, it quickly became cumbersome
to have to split up the import just to pull in theming imports.

Since theming functionality is partially built-in by default in emotion v8
via supporting `p => p.theme` etc, I think it makes sense to go the rest
of the way and re-export `emotion-theming` for ease of use.

update snapshots since the file contents changed
@quantizor
Copy link
Contributor Author

@mitchellhamilton okay, I converted withTheme and ThemeProvider into factory functions... but I don't really understand how babel-macro works. Mind giving some guidance on how to get the Preact part done?

@emmatown
Copy link
Member

emmatown commented Dec 22, 2017

@probablyup babel-macros isn't related to this. First, could you remove createTheming and change it to be separate factories, having them as separate factories means we can add the pure flag so they can be individually removed if they're not used. I should have said this before but could you base this on the instances branch and only export the factories from emotion-theming and then in react-emotion and preact-emotion create and export withTheme and emotionTheming. Also, I know before I said to have a channel option but I think let's just make the only option be the React-like library, especially if we change things in the future because of createContext and etc.

UPDATE: instances is now on master

@quantizor
Copy link
Contributor Author

I'm not going to be able to work on this for a while, so just going to close.

@quantizor quantizor closed this Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants