Class: ContainerProvider<E>
Defined in: src/wirestate-lit/provision/container-provider.ts:83
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 entries 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: { entries: [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/provision/container-provider.ts:98
Parameters
| Parameter | Type | Description |
|---|---|---|
host | E | The host element. |
options | ContainerProviderOptions | Provisioning options. |
Returns
ContainerProvider<E>
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/provision/container-provider.ts:222
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/provision/container-provider.ts:130
Returns
void
Implementation of
ReactiveController.hostConnectedOverrides
ContextProvider.hostConnectedhostDisconnected()
hostDisconnected(): void;Defined in: src/wirestate-lit/provision/container-provider.ts:142
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: CreateContainerOptions): void;Defined in: src/wirestate-lit/provision/container-provider.ts:191
Replaces the managed container config.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | CreateContainerOptions | 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.
setValue()
setValue(container: Container, force?: boolean): void;Defined in: src/wirestate-lit/provision/container-provider.ts:154
Parameters
| Parameter | Type |
|---|---|
container | Container |
force? | boolean |
Returns
void
Overrides
ContextProvider.setValueProperties
config
protected config: Maybe<CreateContainerOptions>;Defined in: src/wirestate-lit/provision/container-provider.ts:89
container
protected container: Maybe<Container>;Defined in: src/wirestate-lit/provision/container-provider.ts:90
host
protected readonly host: E;Defined in: @lit/context:
Inherited from
ContextProvider.hostlifecycle
protected readonly lifecycle: ProvisionLifecycle;Defined in: src/wirestate-lit/provision/container-provider.ts:87
onContextRequest
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