Open trusktr opened 2 months ago
Maybe this is worthy of discussion for the actual context protocol itself, so I opened an issue and linked it to here for more details:
I just realized too that an element-based API could provide nide type safety in TypeScript-powered templating. All frameworks have the machinery for type definitions of custom elements and their props (typically via JSX types even if the framework's syntax is not JSX). This is nice because a CE lib author can add a JSX type definition for an element such as <foo-context>
along with the type for its value
prop/attribute, and framework users will have type checking in their type-capable template systems. It requires multiple JSX definitions though, as frameworks have varying shapes for their JSX interfaces.
As an example, I defined the Solid JSX types for Lume's <lume-camera-rig>
element here, while the React JSX types are here.
For example, I think it would be easier to use context with any custom element system regardless of the authoring experience if users could use elements, because all authoring experiences standardize on HTML.
As an example,
solid-element
allows writing custom elements withfunction
instead ofclass
, so it is impossible to apply a class mixin to a custom element written withsolid-element
.However, providing an element-based API would make context fully agnostic of element authoring patterns.
Here's a code sample. This next piece of code is higher up in the tree in some ancestor custom element:
Now here's the tree inside of
any-other-element
:As we can see by the example,
React example:
etc.
Some custom element libraries may ship with their own set of context to make composition and mixing and matching of their features flexible, and regardless if we're in React/Vue/Svelte/etc we'd want to be able to configure and use that custom element library.
For example,
foo-context
andany-other-element
might both come from a library. A user would be able to configure the elements how they see fit:vs
A custom element library could also abstract it more, as needed, regardless of end user framework: