Skip to content

Class: SubContainerProvider<E>

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

Reactive controller that provides a managed child container.

Remarks

The child container inherits parent bindings but owns its own buses, seeds, and lifecycle. It is recreated when the parent container changes.

Child containers activate all entries by default unless activate is set. Before connect and after disconnect, the context value is undefined.

Example

typescript
class MyComponent extends LitElement {
  private container = new SubContainerProvider(this, {
    config: {
      entries: [AuthService, UserService],
      seeds: [[AuthService, { role: "admin" }]],
    },
  });
}

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 SubContainerProvider<E>(host: E, options: SubContainerProviderOptions): SubContainerProvider<E>;

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

Parameters

ParameterTypeDescription
hostEThe host element.
optionsSubContainerProviderOptionsProvisioning options, including child entries, eager activations, and seeds.

Returns

SubContainerProvider<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

createContainer()

ts
protected createContainer(): void;

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

Replaces the currently provided child container with a new one derived from the latest parent context.

Returns

void


destroyContainer()

ts
protected destroyContainer(): void;

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

Destroys the currently provided child container.

Returns

void


hostConnected()

ts
hostConnected(): void;

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

Returns

void

Implementation of

ts
ReactiveController.hostConnected

Overrides

ts
ContextProvider.hostConnected

hostDisconnected()

ts
hostDisconnected(): void;

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

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: {
  activate?: ContainerActivation;
  entries: readonly (
     | Newable<object>
    | InjectableDescriptor<unknown, unknown>)[];
  seeds?: SeedEntries;
}): void;

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

Replaces the managed child-container config.

Parameters

ParameterTypeDescription
config{ activate?: ContainerActivation; entries: readonly ( | Newable<object> | InjectableDescriptor<unknown, unknown>)[]; seeds?: SeedEntries; }Child-container creation options to use from now on.
config.activate?ContainerActivationServices to activate (get from container) immediately after binding. Remarks Defaults to true, activating all provided entries. Pass false to skip eager activation, or pass an array to activate specific entries.
config.entriesreadonly ( | Newable<object> | InjectableDescriptor<unknown, unknown>)[]List of service entries to bind to the container.
config.seeds?SeedEntriesSeed data to apply to the container before binding. Applied before entries are bound so that @Inject(SEEDS_TOKEN) works during activation.

Returns

void

Remarks

When the provider is not currently provisioning a child container, the config is stored for the next connect. When it is active, the current child container is deprovisioned, destroyed, and recreated from the new config.


setValue()

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

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

Parameters

ParameterType
containerContainer
force?boolean

Returns

void

Overrides

ts
ContextProvider.setValue

Properties

config

ts
protected config: {
  activate?: ContainerActivation;
  entries: readonly (
     | Newable<object>
    | InjectableDescriptor<unknown, unknown>)[];
  seeds?: SeedEntries;
};

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

NameTypeDescriptionDefined in
activate?ContainerActivationServices to activate (get from container) immediately after binding. Remarks Defaults to true, activating all provided entries. Pass false to skip eager activation, or pass an array to activate specific entries.src/wirestate-lit/provision/sub-container-provider.ts:53
entriesreadonly ( | Newable<object> | InjectableDescriptor<unknown, unknown>)[]List of service entries to bind to the container.src/wirestate-lit/provision/sub-container-provider.ts:44
seeds?SeedEntriesSeed data to apply to the container before binding. Applied before entries are bound so that @Inject(SEEDS_TOKEN) works during activation.src/wirestate-lit/provision/sub-container-provider.ts:59

consumer

ts
protected readonly consumer: ContextConsumer<{
  __context__: Container;
}, E>;

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


destroyed

ts
protected destroyed: boolean = true;

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


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/sub-container-provider.ts:91


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

parent

ts
protected parent: Maybe<Container> = null;

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


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