Giter VIP home page Giter VIP logo

Comments (4)

robinweser avatar robinweser commented on May 24, 2024 1

@MicheleBertoli @johanneslumpe Got a new idea on my mind. The proposed API design seems quite fine. I guess its no real difference if the changeTheme/updateTheme is returned by theming() or if it is a method of the renderer itself, though being returned by theming seems more transparent.

To do style rehydration I thought about actually providing another enhancer which additionally tracks all rule(id)-props combinations. This would decouple both features which can be useful each by their own.
This would look sth. like:

const renderer = createRenderer({
  enhancers: [ rehydrate() ]
})

let someVar = 'red'

const rule = props => ({
  color: props.color,
  backgroundColor: someVar
})

renderer.renderRule(rule, { fontSize: '15px' }) // => 'c0 c0-foo'
// .c0 { background-color: red }

someVar = 'blue'

renderer.rehydrate()
// .c0 { background-color: blue }

See #71

from fela.

MicheleBertoli avatar MicheleBertoli commented on May 24, 2024

Well done, I love the solution.

Did you already think about a function to change the theme?

from fela.

johanneslumpe avatar johanneslumpe commented on May 24, 2024

@rofrischmann @MicheleBertoli
What do you think about this:

Instead of returning an enhancer directly, theming(theme) could return an object with a shape like { enhancer, changeTheme } . changeTheme would be a function which takes a new theme as a parameter to allow on the fly theme changes. That function could then easily be passed down via context in react for example (or via any other way in other frameworks).

The only downside I see here (in a react context) is that this change wouldn't cause a re-render because it's outside of react. This could partially be mitigated by keeping the theme object in a redux store for example, but it still might not force a complete re-render.

from fela.

robinweser avatar robinweser commented on May 24, 2024

I thought about adding renderer.updateTheme(theme) to the enhancer to trigger theme updates, but I am yet not sure how to rehydrate all styles. One idea would be to just clear all styles and rerender everything (e.g. using forceUpdate on the <Provider />.
Right now the rendered & cached CSS is compressed so I can not imply the used theme afterwards.

I will have to test this in a real world use case though.

Update: Seems like @johanneslumpe was faster :P But still we have identical ideas I guess :P

from fela.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.