Class: ContainerProvider<E>
Defined in: src/wirestate-lit/container/container-provider.ts:71
Reactive controller that provides a root container through Lit context.
Remarks
Two modes:
- External
container: published while connected, provisioned, never disposed. - Managed
config: created on connect, provisioned, disposed on disconnect.
Managed containers activate all bindings by default. Before connect and after disconnect, the context value is undefined.
Example
import { Injectable } from "@wirestate/core";
import { ContainerProvider } from "@wirestate/lit";
import { LitElement } from "lit";
@Injectable()
class CounterService {}
class AppRoot extends LitElement {
private readonly provider = new ContainerProvider(this, {
config: { bindings: [CounterService] },
});
}Extends
ContextProvider<typeofContainerContext,E>
Type Parameters
| Type Parameter | Default type |
|---|---|
E extends ReactiveControllerHost & HTMLElement | ReactiveControllerHost & HTMLElement |
Implements
ReactiveController
Accessors
value
Get Signature
get value(): T;Defined in: @lit/context:
Returns
T
Set Signature
set value(v: T): void;Defined in: @lit/context:
Parameters
| Parameter | Type |
|---|---|
v | T |
Returns
void
Inherited from
ContextProvider.valueConstructors
Constructor
new ContainerProvider<E>(host: E, options: ContainerProviderOptions): ContainerProvider<E>;Defined in: src/wirestate-lit/container/container-provider.ts:86
Parameters
| Parameter | Type | Description |
|---|---|---|
host | E | The host element. |
options | ContainerProviderOptions | Provisioning options. |
Returns
ContainerProvider<E>
Throws
WirestateError If neither container nor config is provided.
Overrides
ContextProvider<typeof ContainerContext, E>.constructorMethods
addCallback()
addCallback(
callback: ContextCallback<Container>,
consumerHost: Element,
subscribe?: boolean): void;Defined in: @lit/context:
Parameters
| Parameter | Type |
|---|---|
callback | ContextCallback<Container> |
consumerHost | Element |
subscribe? | boolean |
Returns
void
Inherited from
ContextProvider.addCallbackclearCallbacks()
clearCallbacks(): void;Defined in: @lit/context:
Returns
void
Inherited from
ContextProvider.clearCallbacksdestroyManagedContainer()
protected destroyManagedContainer(container: Container): void;Defined in: src/wirestate-lit/container/container-provider.ts:245
Destroys the currently owned managed container.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Managed container to deprovision and dispose. |
Returns
void
hostConnected()
hostConnected(): void;Defined in: src/wirestate-lit/container/container-provider.ts:112
Returns
void
Implementation of
ReactiveController.hostConnectedOverrides
ContextProvider.hostConnectedhostDisconnected()
hostDisconnected(): void;Defined in: src/wirestate-lit/container/container-provider.ts:134
Called when the host is disconnected from the component tree. For custom element hosts, this corresponds to the disconnectedCallback() lifecycle, which is called the host or an ancestor component is disconnected from the document.
Returns
void
Implementation of
ReactiveController.hostDisconnectedsetConfig()
setConfig(config: ContainerConfig): void;Defined in: src/wirestate-lit/container/container-provider.ts:207
Replaces the managed container config.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | ContainerConfig | Container creation options to use from now on. |
Returns
void
Remarks
External-container providers cannot switch to managed mode. Connected managed providers replace the current container immediately. Disconnected managed providers store the config for the next connection.
Throws
WirestateError If this provider was created with an external container and cannot switch to managed mode.
setValue()
setValue(container: Container, force?: boolean): void;Defined in: src/wirestate-lit/container/container-provider.ts:161
Replaces the external container published by this provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | External container to publish. |
force? | boolean | Whether Lit context consumers should be notified even if the value is unchanged. |
Returns
void
Remarks
Only external-container providers can use this method. Connected providers deprovision the previous container, provision the new one, and publish it through context. Disconnected providers store the container for the next connection.
Throws
WirestateError If this provider owns managed containers.
Overrides
ContextProvider.setValueProperties
config
protected config: Maybe<ContainerConfig>;Defined in: src/wirestate-lit/container/container-provider.ts:75
container
protected container: Maybe<Container>;Defined in: src/wirestate-lit/container/container-provider.ts:76
host
protected readonly host: E;Defined in: @lit/context:
Inherited from
ContextProvider.hostonContextRequest
onContextRequest: (ev: ContextRequestEvent<{
__context__: unknown;
}>) => void;Defined in: @lit/context:
Parameters
| Parameter | Type |
|---|---|
ev | ContextRequestEvent<{ __context__: unknown; }> |
Returns
void
Inherited from
ContextProvider.onContextRequestonProviderRequest
onProviderRequest: (ev: ContextProviderEvent<{
__context__: unknown;
}>) => void;Defined in: @lit/context:
When we get a provider request event, that means a child of this element has just woken up. If it's a provider of our context, then we may need to re-parent our subscriptions, because is a more specific provider than us for its subtree.
Parameters
| Parameter | Type |
|---|---|
ev | ContextProviderEvent<{ __context__: unknown; }> |
Returns
void
Inherited from
ContextProvider.onProviderRequestsubscriptions
protected readonly subscriptions: Map<ContextCallback<Container>, CallbackInfo>;Defined in: @lit/context:
Inherited from
ContextProvider.subscriptionsupdateObservers
updateObservers: () => void;Defined in: @lit/context:
Returns
void
Inherited from
ContextProvider.updateObservers