You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remark: I haven't found a lot of conversation about "context support in lit-element" - just #46 and this seems quite old.
Description
If you develop a non-trivial component suite with React, very often it's necessary that you not just export the components themselves but also the context objects that are needed for those components (at least if you do not wrap all those context objects in custom hooks and special components). Means: Those context objects are a very important part of your published component suite.
Any plans/chance that lit-element will provide out-of-the-box support for contexts in near future too?
Of course, something like this is doable in userland, but then everybody has her own solution and for each solution you may need some special adapters or whatever, which would be (and actually currently is) quite annoying. A de facto standard would be much, much, much, much better.
Of course the base context API should be framework agnostic, so that the core types/interfaces of that context API could also be used outside of the lit-element world.
Frankly, I currently have no idea whether such a context API could be implemented performant for SSR.
If this topic may be of interest please find here some more details
// One of many possible context APIs// framework agnostic// maybe an additional readonly property `uuid` would also be usefultypeContext<T>={readonlykind: 'context',readonlydefaultValue: T}// framwork agnosticfunctioncreateContext<T>(defaultValue: T): Context<T>{returnObject.freeze({kind: 'context',
defaultValue
})}// framework agnosticfunctioncreateProvider<T>(): CustomElementConstructor{
....}// Here just for example a @context decorator to handle the// context value injections. Of course this could be also handled// in a completely different non-decorator-based way.// More infos about that decorator will follow in the example below.// Not framework agnostic!functioncontext(...){ ... }/************************************* * Here's a little example * *************************************/enumTheme{Light='light',Dark='dark'}constThemeCtx=createContext(Theme.Light)constThemeProvider=createProvider(ThemeCtx)customElements.define('theme-provider',ThemeProvider)
@customElement('theme-info')classThemeInfoextendsLitElement{
@context(ThemeCtx)privatetheme=ThemeCtx.defaultValuerender(){returnhtml`<div>Current theme: ${this.theme}</div>`}}constoutput=html`<theme-provider.value=${Theme.Dark}><h3>Context demo</h3><theme-info></theme-info></theme-provider>`
Find here some remarks on how the context API of the web component library `haunted` could be transferred to a framework agnostic API
Please find here the important parts of the context API in `haunted`:
Link
The most important part is this (please be aware that nothing is framework agnostic here):
constcontextEvent='haunted.context';interfaceContext<T>{Provider: ComponentConstructor<{}>;Consumer: ComponentConstructor<ConsumerProps<T>>;defaultValue: T;}interfaceContextDetail<T>{Context: Context<T>;callback: (value: T)=>void;// These properties will not exist if a context consumer lacks a providervalue: T;unsubscribe?: (this: Context<T>)=>void;}
A framework agnostic variant of that could for example look as follows:
Core context API (=> types/interfaces + description how underlying event handling should work) must be framework agnostic - no need to share a concrete implementation
Should work fine and performant with SSR
The text was updated successfully, but these errors were encountered:
Closing this issue since there's an active PR where this is being developed and refined. Please feel free to kick the tires on that and post feedback. Thanks!
Remark: I haven't found a lot of conversation about "context support in lit-element" - just #46 and this seems quite old.
Description
If you develop a non-trivial component suite with React, very often it's necessary that you not just export the components themselves but also the context objects that are needed for those components (at least if you do not wrap all those context objects in custom hooks and special components). Means: Those context objects are a very important part of your published component suite.
Any plans/chance that
lit-element
will provide out-of-the-box support for contexts in near future too?Of course, something like this is doable in userland, but then everybody has her own solution and for each solution you may need some special adapters or whatever, which would be (and actually currently is) quite annoying. A de facto standard would be much, much, much, much better.
Of course the base context API should be framework agnostic, so that the core types/interfaces of that context API could also be used outside of the
lit-element
world.Frankly, I currently have no idea whether such a context API could be implemented performant for SSR.
If this topic may be of interest please find here some more details
Find here some remarks on how the context API of the web component library `haunted` could be transferred to a framework agnostic API
Please find here the important parts of the context API in `haunted`: Link
The most important part is this (please be aware that nothing is framework agnostic here):
A framework agnostic variant of that could for example look as follows:
Acceptance criteria
The text was updated successfully, but these errors were encountered: