Giter Club home page Giter Club logo

Comments (14)

developit avatar developit commented on August 15, 2024 3

This is a good pattern. If it's useful to you, preact now exports createElement() (same as h()). That means all the major VDOM libs support { createElement, cloneElement, Component, render } - so your factory could just accept that as an object if it's any easier. I wrote a post about the technique and how you can potentially even use a Webpack loaded to accomplish this too.

from theming.

robinweser avatar robinweser commented on August 15, 2024 1

I am no expert in either Preact or Inferno, but I thought that using preact-compat is actually not the most recommended way to use Preact in general, but rather a quick production-replacement for React apps.

Most likely it's just the different createElement import and some minor changes. Check out how we did it with Fela e.g. the createComponent-HOC:

(See how the abstract factory contains all the logic while the actual bindings simply add in the correct APIs)

But I also see @kof's point with different packages for any React lib.

from theming.

robinweser avatar robinweser commented on August 15, 2024 1

Something like this? That would mean, we only ship the abstract factory and the library itself decides what to use?

React

import { createElement, Component } from 'react'

const theming = themingFactory({
  createElement, 
  Component
})

// where theming ships the APIs
const { withTheme, ThemeProvider } = theming

Preact

import { h, Component } from 'preact'

const theming = themingFactory({
  createElement: h, 
  Component
})

// where theming ships the APIs
const { withTheme, ThemeProvider } = theming

(The examples are just for demonstration, might not includes every detail, but shows the idea)

from theming.

kof avatar kof commented on August 15, 2024

What exactly is needed to support preact and inferno out of the box? I think we all want it and if its not too special it might be ok to keep it all here in this repo.

from theming.

kof avatar kof commented on August 15, 2024

Preact has preact-compat, there should be no need for all this preact-* packages. Something goes wrong if every react package willl create preact- and inferno- packages. cc @developit

from theming.

iamstarkov avatar iamstarkov commented on August 15, 2024

hi @rofrischmann, does abstracting mean that we will have 3 packages, like {react,preact,inferno}-theming?

from theming.

iamstarkov avatar iamstarkov commented on August 15, 2024

i see, thats neat https://github.com/rofrischmann/fela/blob/master/packages/react-fela/src/createComponent.js

from theming.

kof avatar kof commented on August 15, 2024

@rofrischmann can you help with this? You are already a collaborator on this project.

from theming.

robinweser avatar robinweser commented on August 15, 2024

If youโ€™re fine with 3 different packages (themig-* or *-theming where * = react/preact/inferno) I can help here, but after ReactiveConf ofc :p
Could talk there as well

from theming.

kof avatar kof commented on August 15, 2024

What other choices do we have? Can it be a functional way? Like setReactLibrary() or something?

from theming.

kof avatar kof commented on August 15, 2024

Sounds like a good solution! Way better than to produce separate packages or even repositories ๐Ÿ˜…

from theming.

robinweser avatar robinweser commented on August 15, 2024

Well it really depends. If this package is only for library authors, the above example is the best solution by far, but if you want to serve direct end-user as well, separate packages for each library are much better in terms of UX/DX => "install & use".
Thanks to tools like Lerna, managing separate packages is pretty much as if its just one.
But I assume theming should only be used by libs anyways so we can use the factory pattern.

from theming.

kof avatar kof commented on August 15, 2024

I assume we target first of all the lib authors. If we keep react by default, most regular users still don't have to do much. Also using a factory is not the end of the world.

from theming.

developit avatar developit commented on August 15, 2024

Just a note: because preact exports createElement in version 7+, you can do this:

import * as preact from 'preact'
const theming = themingFactory(preact)
const { withTheme, ThemeProvider } = theming
import * as react from 'react'
const theming = themingFactory(react)
const { withTheme, ThemeProvider } = theming

That'll have the added benefit of giving you access to cloneElement() in your factory.

from theming.

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.