-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Broadcast React theme changes through shouldComponentUpdate barriers #239
Conversation
Thank you! I will check it as soon as possible, but I'll be away for 1,5 weeks sadly. Can you quickly answer these questions, then I might release it today! Does it change any behavior (is there any breaking change)? Greets, Robin :) |
@rofrischmann No breaking changes. I've confirmed this by swapping it in to my project. Only difference is the bug is fixed :) Package size would be increased by the size of the react-broadcast lib, which is pretty tiny. |
Is this migrated to |
It seams this has been removed. Is there a way this can be reimplemented? |
Definitely an idea we should invest some time again. It was removed as it did not cover all cases and therefore didn't work properly. |
What about implementing it the way glamorous or styled-components did (they seam to have the same approach)? |
For now i wrote my own ThemeProvider with a custom You override the theme prop in https://github.com/rofrischmann/fela/blob/master/packages/fela/src/bindings/createComponentFactory.js#L73. |
Would you mind sharing those changes? I was about to implement theming but sadly they're still not available for preact/inferno abstractions. |
I basically recreated it using the approach from glamurous
And my custom createComponent looks like // createComponent.js
import { PropTypes, createElement } from 'react'
import { createComponentFactory } from 'fela'
import withTheme from 'hocs/withTheme'
const componentFactory = createComponentFactory(createElement, {
renderer: PropTypes.object,
})
export default function (
rule,
type,
passThroughProps
) {
return withTheme(componentFactory(rule, type, passThroughProps))
} |
If anyone wants a working solution now, I created Freyja, which is a convenience layer around Fela, and solves my three biggest issues with Fela:
It's incredibly simple to use and has my favourite API: styles are a single function that returns an object, and the keys of those that object become your className accessors: import withStyles from 'freyja'
const styles = ({ theme, ...props }) => ({
wrapper: { backgroundColor: theme.colors.red },
title: { ...theme.typography.h1 }
})
const Title = ({ title, styles }) =>
<div className={styles.wrapper}>
<h1 className={styles.title}>{title}</h1>
</div>
export default withStyles(styles)(Title) And as an added bonus it has built in memoization of rule rendering, and comes with some optional helper methods, such as fluidType and pseudo-element styling and a few others, which I often add to my theme object to make styling easier. |
@benoneal - one downside to using the API you outlined above is that it wont enjoy the optimizations afforded by |
@TxHawks Sure. Though Freyja does memoize the rendering of styles per key, which optimizes even for dynamic styles. In my applications I rarely, if ever, have purely static styles, perhaps excepting the most trivial components. I make highly interactive and runtime cusomizable interfaces so almost everything can change based on props and dynamic themes. I imagine if your use-case were heavily dominated by static styles and had a lot of hot rendering paths, the optimization provided by that plugin might beat out raw memoization enough that it was worth the effort of wrapping everything in the |
@benoneal thx i will use freyja a an inspiration (we don't need the extra vendor prefixing) |
@rofrischmann nevermind didn't saw #302 |
No description provided.