-
Notifications
You must be signed in to change notification settings - Fork 8
Expose a minimal, shared reconciler interface to encourage component reuse #35
Comments
This is a really neat idea! It means that, if we have those consistent underlying primitives, you could have a whole ecosystem of components that work independently of the underlying infrastructure. It would be pretty magical if you could build a component that works across Web, Desktop, Mobile, Native Widgets, GL Widgets, etc 🔥
Yes, I think this is the challenge. How do we balance exposing enough capabilities of the primitives to make them usable, while not exposing so many that it becomes cumbersome to use in general? Those references you posted are really helpful - seems like a lot of thought has been put into those.
I like this - it also might mean a simpler starting point - someone who just wants to play with
I think I could see these primitives living either You're definitely right - the lower in the dependency chain it is, the easier it is to apply to projects in general. So I guess the next steps here are:
Lots of potential here... thanks for thinking about and proposing this @jchavarri ! |
I definitely like the idea and started thinking about it for mostly 'utility' stuff like color and style. With reconcilers, I'm not sure there's something that could be factored out to an extent that would make it meaningfully reusable. I'd love to be proved wrong and see a concept built for native elements, because ultimately html already is a unifying interface. |
@bryphe I've been thinking a bit more about what can be done to maximize component reuse between different environments. These are the different parts that I identified that would be involved in the pursuit of that goal:
The first two seem to be a hard requirement to get any component reuse. The third one consists on dependencies of the primitives in
@bryphe Keeping the points above in mind, I think the reach of this interface would escape the intent of
@rauanmayemir If the goal is to maximize component reuse across environments, anything browser specific would need to remain behind this interface, be it CSS or DOM related concerns. That means leaving behind a ton of upsides, but HTML and CSS are so pervasive (and different to anything else) that including them in any way in this interface would probably kill any chance of reuse. I think the fact that |
@jchavarri I think you misunderstood, what you wrote is my thinking, too. :) I meant to say that I wasn't able to envision truly shareable primitives I could use on native side, so tabled the idea for now. But I'd be happy to follow |
Ah, sorry for misunderstanding! 🙂 I insisted on that point because I've thought many times in the past that one of the missed opportunities from React was precisely this: because it started as a browser based library, the "host components" were all DOM element tags based. Later on, they were able to split the library into I agree with you that the path to component reusability across platforms is not a trivial one ( |
Cross posting from https://gist.github.com/lpalmes/8f771d2a700bd2a1172d73286ec75b19#gistcomment-2798693: Some thoughts: Supporting two models (class-based and hooks-based model) or just oneI think that creating a shared interface between reconcilers will be very challenging on its own, let alone if we try to bake the two models React supports today: the class components, and the functional components + hooks. Both models are pretty much equivalent in their expressiveness, but very different on their API. It seems that functional+hooks will get more momentum over time so I think I would prefer to bet just on that model for simplicity. I could be wrong though about that momentum. Interface vs implementationThe Reason type system provides a way to define types interfaces, and we could leave to each reconciler the details on how they want to implement it. For example, the I tried to start defining in #35 (comment) the different parts of this interface. What would be the minimal interface that we could define so allow individual exploration in the different reconcilers, but still while allowing for a meaningful % of user-created components to be reused across the reconcilers? Does that interface even exist? Find a balance between sharing too much vs too fewThese are some of the areas where I think we could find a shared interface definition, but it's challenging to do so without restricting too much each reconciler evolution:
|
While working on #34 I updated the DOM reconciler example to have its primitives look more like the ones in revery:
https://github.com/bryphe/reason-reactify/blob/60e270060db3980a833d4a62b5750c7b5e540855/examples/dom/WebReconciler.re#L17-L20
revery is already exposing CSS-like styles, and colors.
This made me think that, if there was a common interface that exposed the type for a minimal, shared set of primitives, it could be possible to have 100% reusable components across different reconcilers, as long as those primitives remain the same and the components themselves don't use environment-dependent APIs. Another upside would be the familiarity with these primitives so moving from one platform to another would have less friction.
The downsides of having this common interface would be that specific environments could put back-pressure onto these primitives, to promote new controversial primitives to get included, or some attributes / types are modified to satisfy one specific reconciler, but that might be unavailable in other platforms.
In any case, this "universal interface" would be optional, so reconcilers authors could always decide if they want their reconciler to matche this interface or not.
I'm also not sure if the interface should live in
reason-reactify
, or better inrevery
. I think the "lower" it is defined on the dependency chain, the more chances to increase the reuse of platform-agnostic components.References:
react-primitives
: . 10 primitives reusable across React applications.react-native-web
: much more expansive than React Primitivesreact-sketchapp
docsstyled-components/primitives
: And the announcement blog post.emotion-primitives
glamorous-primitives
The text was updated successfully, but these errors were encountered: