Function: injection()
Call Signature
function injection<T>(token: ServiceToken<T>): InjectionDecorator<T>;Defined in: src/wirestate-lit/consumption/injection.ts:101
Injects a container value into a Lit element property.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
token | ServiceToken<T> | Token to inject, or options carrying the token plus optional/fallback. |
Returns
Lit property decorator.
Remarks
Follows the nearest container context. Throws when the token is not bound. Pass optional to assign undefined on a miss, or a fallback (which implies optional) to assign a default.
Example
import { injection } from "@wirestate/lit";
import { LitElement } from "lit";
class MyElement extends LitElement {
@injection(MyService)
private service!: MyService;
@injection({ token: MyService, optional: true })
private maybeService?: MyService;
@injection({ token: UserName, fallback: "guest" })
private name!: string;
}Call Signature
function injection<T>(options: {
fallback?: undefined;
optional?: false;
token: ServiceToken<T>;
}): InjectionDecorator<T>;Defined in: src/wirestate-lit/consumption/injection.ts:102
Injects a container value into a Lit element property.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
options | { fallback?: undefined; optional?: false; token: ServiceToken<T>; } |
options.fallback? | undefined |
options.optional? | false |
options.token | ServiceToken<T> |
Returns
Lit property decorator.
Remarks
Follows the nearest container context. Throws when the token is not bound. Pass optional to assign undefined on a miss, or a fallback (which implies optional) to assign a default.
Example
import { injection } from "@wirestate/lit";
import { LitElement } from "lit";
class MyElement extends LitElement {
@injection(MyService)
private service!: MyService;
@injection({ token: MyService, optional: true })
private maybeService?: MyService;
@injection({ token: UserName, fallback: "guest" })
private name!: string;
}Call Signature
function injection<T>(options: {
fallback?: undefined;
optional: true;
token: ServiceToken<T>;
}): InjectionDecorator<Optional<T>>;Defined in: src/wirestate-lit/consumption/injection.ts:107
Injects a container value into a Lit element property.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
options | { fallback?: undefined; optional: true; token: ServiceToken<T>; } |
options.fallback? | undefined |
options.optional | true |
options.token | ServiceToken<T> |
Returns
InjectionDecorator<Optional<T>>
Lit property decorator.
Remarks
Follows the nearest container context. Throws when the token is not bound. Pass optional to assign undefined on a miss, or a fallback (which implies optional) to assign a default.
Example
import { injection } from "@wirestate/lit";
import { LitElement } from "lit";
class MyElement extends LitElement {
@injection(MyService)
private service!: MyService;
@injection({ token: MyService, optional: true })
private maybeService?: MyService;
@injection({ token: UserName, fallback: "guest" })
private name!: string;
}Call Signature
function injection<T, F>(options: {
fallback: InjectionFallback<F>;
optional?: boolean;
token: ServiceToken<T>;
}): InjectionDecorator<T | F>;Defined in: src/wirestate-lit/consumption/injection.ts:112
Injects a container value into a Lit element property.
Type Parameters
| Type Parameter |
|---|
T |
F |
Parameters
| Parameter | Type |
|---|---|
options | { fallback: InjectionFallback<F>; optional?: boolean; token: ServiceToken<T>; } |
options.fallback | InjectionFallback<F> |
options.optional? | boolean |
options.token | ServiceToken<T> |
Returns
InjectionDecorator<T | F>
Lit property decorator.
Remarks
Follows the nearest container context. Throws when the token is not bound. Pass optional to assign undefined on a miss, or a fallback (which implies optional) to assign a default.
Example
import { injection } from "@wirestate/lit";
import { LitElement } from "lit";
class MyElement extends LitElement {
@injection(MyService)
private service!: MyService;
@injection({ token: MyService, optional: true })
private maybeService?: MyService;
@injection({ token: UserName, fallback: "guest" })
private name!: string;
}