Skip to content

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 ​

typescript
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 ​

Type Parameters ​

Type ParameterDefault type
E extends ReactiveControllerHost & HTMLElementReactiveControllerHost & HTMLElement

Implements ​

  • ReactiveController

Accessors ​

value ​

Get Signature ​

ts
get value(): T;

Defined in: @lit/context:

Returns ​

T

Set Signature ​

ts
set value(v: T): void;

Defined in: @lit/context:

Parameters ​
ParameterType
vT
Returns ​

void

Inherited from ​

ts
ContextProvider.value

Constructors ​

Constructor ​

ts
new ContainerProvider<E>(host: E, options: ContainerProviderOptions): ContainerProvider<E>;

Defined in: src/wirestate-lit/container/container-provider.ts:86

Parameters ​

ParameterTypeDescription
hostEThe host element.
optionsContainerProviderOptionsProvisioning options.

Returns ​

ContainerProvider<E>

Throws ​

WirestateError If neither container nor config is provided.

Overrides ​

ts
ContextProvider<typeof ContainerContext, E>.constructor

Methods ​

addCallback() ​

ts
addCallback(
   callback: ContextCallback<Container>, 
   consumerHost: Element, 
   subscribe?: boolean): void;

Defined in: @lit/context:

Parameters ​

ParameterType
callbackContextCallback<Container>
consumerHostElement
subscribe?boolean

Returns ​

void

Inherited from ​

ts
ContextProvider.addCallback

clearCallbacks() ​

ts
clearCallbacks(): void;

Defined in: @lit/context:

Returns ​

void

Inherited from ​

ts
ContextProvider.clearCallbacks

destroyManagedContainer() ​

ts
protected destroyManagedContainer(container: Container): void;

Defined in: src/wirestate-lit/container/container-provider.ts:245

Destroys the currently owned managed container.

Parameters ​

ParameterTypeDescription
containerContainerManaged container to deprovision and dispose.

Returns ​

void


hostConnected() ​

ts
hostConnected(): void;

Defined in: src/wirestate-lit/container/container-provider.ts:112

Returns ​

void

Implementation of ​

ts
ReactiveController.hostConnected

Overrides ​

ts
ContextProvider.hostConnected

hostDisconnected() ​

ts
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 ​

ts
ReactiveController.hostDisconnected

setConfig() ​

ts
setConfig(config: ContainerConfig): void;

Defined in: src/wirestate-lit/container/container-provider.ts:207

Replaces the managed container config.

Parameters ​

ParameterTypeDescription
configContainerConfigContainer 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() ​

ts
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 ​

ParameterTypeDescription
containerContainerExternal container to publish.
force?booleanWhether 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 ​

ts
ContextProvider.setValue

Properties ​

config ​

ts
protected config: Maybe<ContainerConfig>;

Defined in: src/wirestate-lit/container/container-provider.ts:75


container ​

ts
protected container: Maybe<Container>;

Defined in: src/wirestate-lit/container/container-provider.ts:76


host ​

ts
protected readonly host: E;

Defined in: @lit/context:

Inherited from ​

ts
ContextProvider.host

onContextRequest ​

ts
onContextRequest: (ev: ContextRequestEvent<{
  __context__: unknown;
}>) => void;

Defined in: @lit/context:

Parameters ​

ParameterType
evContextRequestEvent<{ __context__: unknown; }>

Returns ​

void

Inherited from ​

ts
ContextProvider.onContextRequest

onProviderRequest ​

ts
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 ​

ParameterType
evContextProviderEvent<{ __context__: unknown; }>

Returns ​

void

Inherited from ​

ts
ContextProvider.onProviderRequest

subscriptions ​

ts
protected readonly subscriptions: Map<ContextCallback<Container>, CallbackInfo>;

Defined in: @lit/context:

Inherited from ​

ts
ContextProvider.subscriptions

updateObservers ​

ts
updateObservers: () => void;

Defined in: @lit/context:

Returns ​

void

Inherited from ​

ts
ContextProvider.updateObservers