Skip to content

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

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: { entries: [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/provision/container-provider.ts:98

Parameters

ParameterTypeDescription
hostEThe host element.
optionsContainerProviderOptionsProvisioning options.

Returns

ContainerProvider<E>

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/provision/container-provider.ts:222

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/provision/container-provider.ts:130

Returns

void

Implementation of

ts
ReactiveController.hostConnected

Overrides

ts
ContextProvider.hostConnected

hostDisconnected()

ts
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

ts
ReactiveController.hostDisconnected

setConfig()

ts
setConfig(config: CreateContainerOptions): void;

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

Replaces the managed container config.

Parameters

ParameterTypeDescription
configCreateContainerOptionsContainer 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()

ts
setValue(container: Container, force?: boolean): void;

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

Parameters

ParameterType
containerContainer
force?boolean

Returns

void

Overrides

ts
ContextProvider.setValue

Properties

config

ts
protected config: Maybe<CreateContainerOptions>;

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


container

ts
protected container: Maybe<Container>;

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


host

ts
protected readonly host: E;

Defined in: @lit/context:

Inherited from

ts
ContextProvider.host

lifecycle

ts
protected readonly lifecycle: ProvisionLifecycle;

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


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