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

Quick pass at removing theme generic param #1

Conversation

JakeGinnivan
Copy link

Having a go at just removing the Theme generic param

export interface GlobalProps<Theme> {
styles: InterpolationWithTheme<Theme>
export interface GlobalProps {
styles: Interpolation
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be Interpolation<Emotion.Theme>. With the proposed approach here, in this PR, you indeed don't need to parametrize GlobalProps with Theme but you still need to provide the default theme type~ to Interpolation here (and probably in some other types where you have removed this).

Copy link
Author

Choose a reason for hiding this comment

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

Interpolation defaults to { theme: Emotion.Theme } so should be fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually it doesn't from what I can see - https://github.com/emotion-js/emotion/blob/b81d652e70c8c421aae24e8fb357be6ff16143f0/packages/serialize/types/index.d.ts#L68

In here (for a Global case) it should be just Interpolation<Emotion.Theme> and not Interpolation<{ theme: Emotion.Theme }>

Copy link
Author

Choose a reason for hiding this comment

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

Check out https://github.com/joltmode/emotion/pull/1/files#diff-e68603b09cd6bb7bbc9c8690f15e5392

I updated those types as part of this. But I didn't spend too much time on them, more putting this up as a general idea for joltmode if he wanted to go this way :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha - I think I was looking as original PR @joltmode looking for Interpolation changes 👍

The point about Global stands though.

Copy link
Author

Choose a reason for hiding this comment

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

Dang, I get it. Good catch

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@tomsseisums
Copy link
Owner

tomsseisums commented Nov 11, 2019

So with this change, it is intended that in order to use a theme, one will always have to provide the custom Emotion.Theme definition?

(Or ultimately the module based definition, as @mitchellhamilton suggested here: emotion-js#1609 (comment))

@JakeGinnivan
Copy link
Author

So with this change, it is intended that in order to use a theme, one will always have to provide the custom Emotion.Theme definition?

Yep, the only downside is in say a mono repo where different applications have different themes.
But I’m not sure how well it will work supporting both models at the same time

@tomsseisums
Copy link
Owner

tomsseisums commented Nov 11, 2019

Yep, the only downside is in say a mono repo where different applications have different themes.
But I’m not sure how well it will work supporting both models at the same time

But doesn't that depend on how one configures the monorepo? It's still possible to expose different typings to different sub-projects.

Another topic is how well does the IDE of choice support monorepos and different TypeScript configs.

@JakeGinnivan
Copy link
Author

I was thinking this, project references for instance.

You could basically declare the theme per project, so common code would extend all the themes? Because we can't have a union type I'm not sure how well that would work. Or common code extend a common interface, then leaf projects have a full one?

Something like that could work ok. This is untested territory for me though

@tomsseisums
Copy link
Owner

I guess, what remains until we can merge together, is to settle if this hardcoded global theme can actually operate in the real world. As it is quite an opinionated solution.

As I said, it's fine by me. I bet it's also fine with Jake, as he proposed the changes.

What about you @Andarist and the rest of emotion team?

@Andarist
Copy link
Collaborator

I guess, what remains until we can merge together, is to settle if this hardcoded global theme can actually operate in the real world. As it is quite an opinionated solution.

I believe this is just a matter of proper documentation. This IMHO should be used only if you are an application developer and you have a single theme type. If you want to have different themes (like in a monorepo where you have a single application but teams want to have their "own" them) and if you are a library (built with emotion) developer then you should use a custom theme.

Basically builtin theme has its shortcomings which can't be fixed and problems with it are outlined in emotion-js#973 . It exists only for convenience reasons.

Even if it doesn't matter much - I would prefer using a module and interface augmentation approach over a global one. Also - I'm in the middle of moving those theming APIs into the core package, so maybe it would be better to wait until this is done before proceeding with this one. We highly appreciate your help ❤️

@tomsseisums
Copy link
Owner

tomsseisums commented Nov 12, 2019 via email

@Andarist
Copy link
Collaborator

Or your suggestion is that for such advanced cases, one should roll up their own ThemeContext / ThemeProvider / withTheme / useTheme and other handlers?

Exactly this, because otherwise, you have to deal with theme clashes etc (it's harder to mix 2 components libraries built on top of emotion). With built-in theme you also can't set its default value (so if you are building a component library with theming you have to make your consumer aware that they need to wrap their app with a ThemeProvider or resolve lack of provided theme manually in your components.

@tomsseisums
Copy link
Owner

Went over the docs for emotion-js#973 - yeah, makes so much sense! Good share, thanks!

That clears the path for the remainder of concerns I had with the proposed approach here.

@tomsseisums tomsseisums merged commit 16ae3b7 into tomsseisums:topics/global-theme-type Nov 23, 2019
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.

3 participants