@wirestate/lit 0.6.1 → 0.7.0-experimental.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -2
- package/README.md +88 -70
- package/cjs/development/index.js +412 -320
- package/cjs/development/index.js.map +1 -1
- package/cjs/production/index.js +1 -1
- package/cjs/production/index.js.map +1 -1
- package/esm/development/commands/on-command-controller.js +8 -7
- package/esm/development/commands/on-command-controller.js.map +1 -1
- package/esm/development/commands/on-command.js +7 -6
- package/esm/development/commands/on-command.js.map +1 -1
- package/esm/development/commands/use-on-command.js +7 -7
- package/esm/development/consumption/injection.js +8 -8
- package/esm/development/consumption/injection.js.map +1 -1
- package/esm/development/consumption/use-container.js +40 -0
- package/esm/development/consumption/use-container.js.map +1 -0
- package/esm/development/consumption/use-injection.js +8 -8
- package/esm/development/consumption/use-injection.js.map +1 -1
- package/esm/development/consumption/use-scope.js +44 -0
- package/esm/development/consumption/use-scope.js.map +1 -0
- package/esm/development/context/container-context.js +17 -0
- package/esm/development/context/container-context.js.map +1 -0
- package/esm/development/events/on-event-controller.js +11 -9
- package/esm/development/events/on-event-controller.js.map +1 -1
- package/esm/development/events/on-event.js +11 -8
- package/esm/development/events/on-event.js.map +1 -1
- package/esm/development/events/use-on-events.js +8 -8
- package/esm/development/index.js +9 -7
- package/esm/development/index.js.map +1 -1
- package/esm/development/provision/container-provide.js +68 -0
- package/esm/development/provision/container-provide.js.map +1 -0
- package/esm/development/provision/container-provider.js +74 -0
- package/esm/development/provision/container-provider.js.map +1 -0
- package/esm/development/provision/sub-container-provide.js +56 -0
- package/esm/development/provision/sub-container-provide.js.map +1 -0
- package/esm/development/provision/sub-container-provider.js +93 -0
- package/esm/development/provision/sub-container-provider.js.map +1 -0
- package/esm/development/provision/use-container-provision.js +44 -0
- package/esm/development/provision/use-container-provision.js.map +1 -0
- package/esm/development/provision/use-sub-container-provider.js +34 -0
- package/esm/development/provision/use-sub-container-provider.js.map +1 -0
- package/esm/development/queries/on-query-controller.js +9 -8
- package/esm/development/queries/on-query-controller.js.map +1 -1
- package/esm/development/queries/on-query.js +7 -6
- package/esm/development/queries/on-query.js.map +1 -1
- package/esm/development/queries/use-on-query.js +7 -7
- package/esm/production/commands/on-command-controller.js +1 -1
- package/esm/production/commands/on-command-controller.js.map +1 -1
- package/esm/production/commands/on-command.js.map +1 -1
- package/esm/production/consumption/injection.js +1 -1
- package/esm/production/consumption/injection.js.map +1 -1
- package/esm/production/consumption/use-container.js +1 -0
- package/esm/production/consumption/use-container.js.map +1 -0
- package/esm/production/consumption/use-injection.js +1 -1
- package/esm/production/consumption/use-injection.js.map +1 -1
- package/esm/production/consumption/use-scope.js +1 -0
- package/esm/production/consumption/use-scope.js.map +1 -0
- package/esm/production/context/container-context.js +1 -0
- package/esm/production/context/container-context.js.map +1 -0
- package/esm/production/events/on-event-controller.js +1 -1
- package/esm/production/events/on-event-controller.js.map +1 -1
- package/esm/production/events/on-event.js.map +1 -1
- package/esm/production/index.js +1 -1
- package/esm/production/provision/container-provide.js +1 -0
- package/esm/production/provision/container-provide.js.map +1 -0
- package/esm/production/provision/container-provider.js +1 -0
- package/esm/production/provision/container-provider.js.map +1 -0
- package/esm/production/provision/sub-container-provide.js +1 -0
- package/esm/production/provision/sub-container-provide.js.map +1 -0
- package/esm/production/provision/sub-container-provider.js +1 -0
- package/esm/production/provision/sub-container-provider.js.map +1 -0
- package/esm/production/provision/use-container-provision.js +1 -0
- package/esm/production/provision/use-container-provision.js.map +1 -0
- package/esm/production/provision/use-sub-container-provider.js +1 -0
- package/esm/production/provision/use-sub-container-provider.js.map +1 -0
- package/esm/production/queries/on-query-controller.js +1 -1
- package/esm/production/queries/on-query-controller.js.map +1 -1
- package/esm/production/queries/on-query.js.map +1 -1
- package/index.d.ts +413 -291
- package/package.json +2 -2
- package/esm/development/context/ioc-context.js +0 -17
- package/esm/development/context/ioc-context.js.map +0 -1
- package/esm/development/provision/injectables-provide.js +0 -47
- package/esm/development/provision/injectables-provide.js.map +0 -1
- package/esm/development/provision/injectables-provider-controller.js +0 -123
- package/esm/development/provision/injectables-provider-controller.js.map +0 -1
- package/esm/development/provision/ioc-provide.js +0 -55
- package/esm/development/provision/ioc-provide.js.map +0 -1
- package/esm/development/provision/ioc-provider-controller.js +0 -72
- package/esm/development/provision/ioc-provider-controller.js.map +0 -1
- package/esm/development/provision/use-injectables-provider.js +0 -33
- package/esm/development/provision/use-injectables-provider.js.map +0 -1
- package/esm/development/provision/use-ioc-provision.js +0 -29
- package/esm/development/provision/use-ioc-provision.js.map +0 -1
- package/esm/production/context/ioc-context.js +0 -1
- package/esm/production/context/ioc-context.js.map +0 -1
- package/esm/production/provision/injectables-provide.js +0 -1
- package/esm/production/provision/injectables-provide.js.map +0 -1
- package/esm/production/provision/injectables-provider-controller.js +0 -1
- package/esm/production/provision/injectables-provider-controller.js.map +0 -1
- package/esm/production/provision/ioc-provide.js +0 -1
- package/esm/production/provision/ioc-provide.js.map +0 -1
- package/esm/production/provision/ioc-provider-controller.js +0 -1
- package/esm/production/provision/ioc-provider-controller.js.map +0 -1
- package/esm/production/provision/use-injectables-provider.js +0 -1
- package/esm/production/provision/use-injectables-provider.js.map +0 -1
- package/esm/production/provision/use-ioc-provision.js +0 -1
- package/esm/production/provision/use-ioc-provision.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { ReactiveElement, ReactiveControllerHost, ReactiveController } from '@lit/reactive-element';
|
|
2
|
-
import { ServiceIdentifier, CommandType, CommandHandler, Event, EventType, EventHandler, QueryType, QueryHandler,
|
|
2
|
+
import { ServiceIdentifier, Container as Container$1, WireScope, CommandType, CommandHandler, Event, EventType, EventHandler, QueryType, QueryHandler, CreateContainerOptions, Newable, InjectableDescriptor, SeedEntries } from '@wirestate/core';
|
|
3
3
|
import { ContextProvider, ContextConsumer } from '@lit/context';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Type that can be null.
|
|
7
7
|
*
|
|
8
|
-
* @group
|
|
8
|
+
* @group Types
|
|
9
9
|
*/
|
|
10
|
-
type
|
|
10
|
+
type Optional<T> = T | null;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Value or a promise of that value.
|
|
13
13
|
*
|
|
14
|
-
* @group
|
|
14
|
+
* @group Types
|
|
15
15
|
*/
|
|
16
|
-
type
|
|
16
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Value that can be null or undefined.
|
|
19
19
|
*
|
|
20
|
-
* @group
|
|
20
|
+
* @group Types
|
|
21
21
|
*/
|
|
22
|
-
type
|
|
22
|
+
type Maybe<T> = T | null | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* Helper to extract the interface of a type.
|
|
25
25
|
*
|
|
26
|
-
* @group
|
|
26
|
+
* @group Types
|
|
27
27
|
*/
|
|
28
28
|
type Interface<T> = {
|
|
29
29
|
[K in keyof T]: T[K];
|
|
@@ -31,13 +31,13 @@ type Interface<T> = {
|
|
|
31
31
|
/**
|
|
32
32
|
* Return type for decorators.
|
|
33
33
|
*
|
|
34
|
-
* @group
|
|
34
|
+
* @group Types
|
|
35
35
|
*/
|
|
36
36
|
type DecoratorReturn = void | any;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Ensures that a decorated field matches the type being provided.
|
|
39
39
|
*
|
|
40
|
-
* @group
|
|
40
|
+
* @group Types
|
|
41
41
|
*/
|
|
42
42
|
type FieldMustMatchProvidedType<Obj, Key extends PropertyKey, ProvidedType> = Obj extends Record<Key, infer ConsumingType> ? [ProvidedType] extends [ConsumingType] ? DecoratorReturn : {
|
|
43
43
|
message: "provided type not assignable to consuming field";
|
|
@@ -50,39 +50,43 @@ type FieldMustMatchProvidedType<Obj, Key extends PropertyKey, ProvidedType> = Ob
|
|
|
50
50
|
} : DecoratorReturn;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Represents definition of the injection decorator.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
54
57
|
*
|
|
55
|
-
* @group
|
|
58
|
+
* @group Consumption
|
|
56
59
|
*/
|
|
57
60
|
interface InjectionDecorator<T> {
|
|
58
61
|
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends T>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
|
|
59
62
|
<K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, T>;
|
|
60
63
|
}
|
|
61
64
|
/**
|
|
62
|
-
*
|
|
65
|
+
* Represents options for the {@link injection} decorator.
|
|
63
66
|
*
|
|
64
|
-
* @group
|
|
67
|
+
* @group Consumption
|
|
65
68
|
*/
|
|
66
69
|
interface InjectionOptions<T> {
|
|
67
70
|
/**
|
|
68
|
-
* The service identifier to inject
|
|
71
|
+
* The service identifier to inject.
|
|
69
72
|
*/
|
|
70
73
|
injectionId: ServiceIdentifier<T>;
|
|
71
74
|
/**
|
|
72
|
-
* Whether to subscribe to changes
|
|
75
|
+
* Whether to subscribe to container changes.
|
|
73
76
|
*
|
|
77
|
+
* @remarks
|
|
74
78
|
* If true, the property will be updated if the container in the context changes.
|
|
75
|
-
*
|
|
79
|
+
* Defaults to false.
|
|
76
80
|
*/
|
|
77
81
|
once?: boolean;
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Decorator to inject a service from the IoC container into a Lit element property.
|
|
81
85
|
*
|
|
82
|
-
* @group
|
|
86
|
+
* @group Consumption
|
|
83
87
|
*
|
|
84
|
-
* @param optionsOrInjectionId -
|
|
85
|
-
* @returns
|
|
88
|
+
* @param optionsOrInjectionId - Injection options or service identifier.
|
|
89
|
+
* @returns An instance of {@link InjectionDecorator}.
|
|
86
90
|
*
|
|
87
91
|
* @example
|
|
88
92
|
* ```typescript
|
|
@@ -111,18 +115,56 @@ interface InjectionOptions<T> {
|
|
|
111
115
|
declare function injection<T>(optionsOrInjectionId: InjectionOptions<T> | ServiceIdentifier<T>): InjectionDecorator<T>;
|
|
112
116
|
|
|
113
117
|
/**
|
|
114
|
-
*
|
|
118
|
+
* Represents result of the {@link useContainer} hook.
|
|
119
|
+
*
|
|
120
|
+
* @group Consumption
|
|
121
|
+
*/
|
|
122
|
+
interface UseContainerValue {
|
|
123
|
+
/**
|
|
124
|
+
* The active container from the nearest parent context.
|
|
125
|
+
*/
|
|
126
|
+
value: Container$1;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Hook (consumer) to access the active container from the nearest parent context.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* The returned value updates when the nearest provided container changes.
|
|
133
|
+
*
|
|
134
|
+
* @group Consumption
|
|
135
|
+
*
|
|
136
|
+
* @param host - The host element.
|
|
137
|
+
* @returns An instance of {@link UseContainerValue}.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* class MyElement extends LitElement {
|
|
142
|
+
* private container: UseContainerValue = useContainer(this);
|
|
143
|
+
*
|
|
144
|
+
* public render() {
|
|
145
|
+
* return html`<div>${this.container.value.isBound(MyService)}</div>`;
|
|
146
|
+
* }
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function useContainer<E extends ReactiveControllerHost & HTMLElement>(host: E): UseContainerValue;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Represents options for the {@link useInjection} hook.
|
|
115
154
|
*
|
|
116
|
-
* @group
|
|
155
|
+
* @group Consumption
|
|
117
156
|
*/
|
|
118
157
|
interface UseInjectionOptions<T> {
|
|
119
158
|
/**
|
|
159
|
+
* Whether to subscribe to container changes.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
120
162
|
* If true, the service will be fetched only once when the controller is created.
|
|
121
|
-
*
|
|
163
|
+
* Defaults to false.
|
|
122
164
|
*/
|
|
123
165
|
once?: boolean;
|
|
124
166
|
/**
|
|
125
|
-
* Initial value
|
|
167
|
+
* Initial value before the service is fetched.
|
|
126
168
|
*/
|
|
127
169
|
value?: Optional<T>;
|
|
128
170
|
/**
|
|
@@ -131,9 +173,9 @@ interface UseInjectionOptions<T> {
|
|
|
131
173
|
injectionId: ServiceIdentifier<T>;
|
|
132
174
|
}
|
|
133
175
|
/**
|
|
134
|
-
*
|
|
176
|
+
* Represents result of the {@link useInjection} hook.
|
|
135
177
|
*
|
|
136
|
-
* @group
|
|
178
|
+
* @group Consumption
|
|
137
179
|
*/
|
|
138
180
|
interface UseInjectionValue<T> {
|
|
139
181
|
/**
|
|
@@ -146,13 +188,13 @@ interface UseInjectionValue<T> {
|
|
|
146
188
|
value: T;
|
|
147
189
|
}
|
|
148
190
|
/**
|
|
149
|
-
* Hook (controller) to inject a service from the IoC container
|
|
191
|
+
* Hook (controller) to inject a service from the IoC container.
|
|
150
192
|
*
|
|
151
|
-
* @group
|
|
193
|
+
* @group Consumption
|
|
152
194
|
*
|
|
153
|
-
* @param host -
|
|
154
|
-
* @param optionsOrInjectionId -
|
|
155
|
-
* @returns
|
|
195
|
+
* @param host - The host element.
|
|
196
|
+
* @param optionsOrInjectionId - Injection options or service identifier.
|
|
197
|
+
* @returns An instance of {@link UseInjectionValue}.
|
|
156
198
|
*
|
|
157
199
|
* @example
|
|
158
200
|
* ```typescript
|
|
@@ -179,31 +221,64 @@ interface UseInjectionValue<T> {
|
|
|
179
221
|
declare function useInjection<T extends object, E extends ReactiveControllerHost & HTMLElement>(host: E, optionsOrInjectionId: UseInjectionOptions<T> | ServiceIdentifier<T>): UseInjectionValue<T>;
|
|
180
222
|
|
|
181
223
|
/**
|
|
182
|
-
*
|
|
224
|
+
* Represents result of the {@link useScope} hook.
|
|
225
|
+
*
|
|
226
|
+
* @group Consumption
|
|
227
|
+
*/
|
|
228
|
+
type UseScopeValue = UseInjectionValue<WireScope>;
|
|
229
|
+
/**
|
|
230
|
+
* Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
|
|
231
|
+
*
|
|
232
|
+
* @remarks
|
|
233
|
+
* The returned value updates when the nearest provided container changes.
|
|
183
234
|
*
|
|
184
|
-
*
|
|
235
|
+
* @group Consumption
|
|
185
236
|
*
|
|
186
|
-
* @
|
|
237
|
+
* @param host - The host element.
|
|
238
|
+
* @returns An instance of {@link UseScopeValue}.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* class MyElement extends LitElement {
|
|
243
|
+
* private scope: UseScopeValue = useScope(this);
|
|
244
|
+
*
|
|
245
|
+
* public connectedCallback(): void {
|
|
246
|
+
* super.connectedCallback();
|
|
247
|
+
* this.scope.value.emitEvent("UI_READY");
|
|
248
|
+
* }
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function useScope<E extends ReactiveControllerHost & HTMLElement>(host: E): UseScopeValue;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Represents interface for the {@link onCommand} decorator.
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
259
|
+
*
|
|
260
|
+
* @group Commands
|
|
187
261
|
*/
|
|
188
262
|
interface OnCommandDecorator<D = unknown, R = unknown> {
|
|
189
263
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
|
|
190
264
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
191
265
|
}
|
|
192
266
|
/**
|
|
193
|
-
* Decorator
|
|
267
|
+
* Decorator for Lit element methods that handle a specific command.
|
|
194
268
|
*
|
|
195
|
-
*
|
|
269
|
+
* @remarks
|
|
270
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
196
271
|
*
|
|
197
|
-
* @group
|
|
272
|
+
* @group Commands
|
|
198
273
|
*
|
|
199
|
-
* @param type - the command
|
|
200
|
-
* @returns
|
|
274
|
+
* @param type - Unique identifier of the command to handle.
|
|
275
|
+
* @returns A method decorator function.
|
|
201
276
|
*
|
|
202
277
|
* @example
|
|
203
278
|
* ```typescript
|
|
204
279
|
* class MyElement extends LitElement {
|
|
205
280
|
* @onCommand("SAVE")
|
|
206
|
-
* private
|
|
281
|
+
* private onSave(data: SomeData): void {
|
|
207
282
|
* // handle command
|
|
208
283
|
* }
|
|
209
284
|
* }
|
|
@@ -212,12 +287,13 @@ interface OnCommandDecorator<D = unknown, R = unknown> {
|
|
|
212
287
|
declare function onCommand<D = unknown, R = unknown>(type: CommandType): OnCommandDecorator<D, R>;
|
|
213
288
|
|
|
214
289
|
/**
|
|
215
|
-
*
|
|
290
|
+
* Controller that registers a command handler for the host element's lifetime.
|
|
216
291
|
*
|
|
292
|
+
* @remarks
|
|
217
293
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
218
|
-
*
|
|
294
|
+
* It automatically re-registers if the IoC container is updated.
|
|
219
295
|
*
|
|
220
|
-
* @group
|
|
296
|
+
* @group Commands
|
|
221
297
|
*/
|
|
222
298
|
declare class OnCommandController<D = unknown, R = unknown> implements ReactiveController {
|
|
223
299
|
private bus;
|
|
@@ -226,7 +302,7 @@ declare class OnCommandController<D = unknown, R = unknown> implements ReactiveC
|
|
|
226
302
|
private readonly handler;
|
|
227
303
|
/**
|
|
228
304
|
* @param host - The host element.
|
|
229
|
-
* @param type -
|
|
305
|
+
* @param type - Unique identifier of the command to handle.
|
|
230
306
|
* @param handler - The command handler function.
|
|
231
307
|
*/
|
|
232
308
|
constructor(host: ReactiveElement, type: CommandType, handler: CommandHandler<D, R>);
|
|
@@ -237,9 +313,9 @@ declare class OnCommandController<D = unknown, R = unknown> implements ReactiveC
|
|
|
237
313
|
}
|
|
238
314
|
|
|
239
315
|
/**
|
|
240
|
-
*
|
|
316
|
+
* Represents options for the {@link useOnCommand} hook.
|
|
241
317
|
*
|
|
242
|
-
* @group
|
|
318
|
+
* @group Commands
|
|
243
319
|
*/
|
|
244
320
|
interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
245
321
|
/**
|
|
@@ -252,15 +328,15 @@ interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
|
252
328
|
handler: CommandHandler<D, R>;
|
|
253
329
|
}
|
|
254
330
|
/**
|
|
255
|
-
*
|
|
331
|
+
* Hook that registers a command handler for the host element's lifetime.
|
|
256
332
|
*
|
|
257
|
-
* @group
|
|
333
|
+
* @group Commands
|
|
258
334
|
*
|
|
259
|
-
* @param host -
|
|
260
|
-
* @param options -
|
|
261
|
-
* @param options.type -
|
|
262
|
-
* @param options.handler -
|
|
263
|
-
* @returns
|
|
335
|
+
* @param host - The host element.
|
|
336
|
+
* @param options - Command handling options.
|
|
337
|
+
* @param options.type - The command type to listen for.
|
|
338
|
+
* @param options.handler - The command handler function.
|
|
339
|
+
* @returns The command controller instance.
|
|
264
340
|
*
|
|
265
341
|
* @example
|
|
266
342
|
* ```typescript
|
|
@@ -275,28 +351,34 @@ interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
|
275
351
|
declare function useOnCommand<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnCommandOptions<D, R>): OnCommandController<D, R>;
|
|
276
352
|
|
|
277
353
|
/**
|
|
278
|
-
*
|
|
354
|
+
* Represents type definition for the on-event decorator.
|
|
355
|
+
*
|
|
356
|
+
* @remarks
|
|
357
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
279
358
|
*
|
|
280
|
-
* @group
|
|
359
|
+
* @group Events
|
|
281
360
|
*/
|
|
282
361
|
interface OnEventDecorator<E extends Event = Event> {
|
|
283
362
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, event: E) => void, context: ClassMethodDecoratorContext<This>): void;
|
|
284
363
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
285
364
|
}
|
|
286
365
|
/**
|
|
287
|
-
* Decorator
|
|
366
|
+
* Decorator for Lit element methods that handle events from the event bus.
|
|
288
367
|
*
|
|
289
|
-
* @
|
|
368
|
+
* @remarks
|
|
369
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
370
|
+
*
|
|
371
|
+
* @group Events
|
|
290
372
|
*
|
|
291
373
|
* @param types - Event types to listen for. If omitted, all events will be handled.
|
|
292
|
-
* @returns
|
|
374
|
+
* @returns A method decorator function.
|
|
293
375
|
*
|
|
294
376
|
* @example
|
|
295
377
|
* ```typescript
|
|
296
378
|
* class MyElement extends LitElement {
|
|
297
379
|
* @onEvent()
|
|
298
380
|
* private onMyEvent(event: Event) {
|
|
299
|
-
* console.log(
|
|
381
|
+
* console.log("Event received:", event);
|
|
300
382
|
* }
|
|
301
383
|
* }
|
|
302
384
|
* ```
|
|
@@ -304,9 +386,9 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
304
386
|
* @example
|
|
305
387
|
* ```typescript
|
|
306
388
|
* class MyElement extends LitElement {
|
|
307
|
-
* @onEvent(
|
|
389
|
+
* @onEvent("MY_EVENT_TYPE")
|
|
308
390
|
* private onMyEvent(event: MyEvent) {
|
|
309
|
-
* console.log(
|
|
391
|
+
* console.log("Event received:", event);
|
|
310
392
|
* }
|
|
311
393
|
* }
|
|
312
394
|
* ```
|
|
@@ -314,9 +396,9 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
314
396
|
* @example
|
|
315
397
|
* ```typescript
|
|
316
398
|
* class MyElement extends LitElement {
|
|
317
|
-
* @onEvent([
|
|
399
|
+
* @onEvent(["MY_EVENT_TYPE_1", "MY_EVENT_TYPE_2"])
|
|
318
400
|
* private onMyEvent(event: Event) {
|
|
319
|
-
* console.log(
|
|
401
|
+
* console.log("Event received:", event);
|
|
320
402
|
* }
|
|
321
403
|
* }
|
|
322
404
|
* ```
|
|
@@ -324,11 +406,13 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
324
406
|
declare function onEvent<E extends Event = Event>(types?: EventType | ReadonlyArray<EventType>): OnEventDecorator<E>;
|
|
325
407
|
|
|
326
408
|
/**
|
|
327
|
-
* Controller that subscribes to events
|
|
409
|
+
* Controller that subscribes to events for the host element's lifetime.
|
|
328
410
|
*
|
|
329
|
-
*
|
|
411
|
+
* @remarks
|
|
412
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
413
|
+
* It automatically re-subscribes if the IoC container is updated.
|
|
330
414
|
*
|
|
331
|
-
* @group
|
|
415
|
+
* @group Events
|
|
332
416
|
*/
|
|
333
417
|
declare class OnEventController<E extends Event = Event> implements ReactiveController {
|
|
334
418
|
private bus;
|
|
@@ -336,9 +420,9 @@ declare class OnEventController<E extends Event = Event> implements ReactiveCont
|
|
|
336
420
|
private readonly types;
|
|
337
421
|
private readonly handler;
|
|
338
422
|
/**
|
|
339
|
-
* @param host -
|
|
340
|
-
* @param types -
|
|
341
|
-
* @param handler -
|
|
423
|
+
* @param host - The host element.
|
|
424
|
+
* @param types - Event types to listen for. If null, all events will be handled.
|
|
425
|
+
* @param handler - The event handler function.
|
|
342
426
|
*/
|
|
343
427
|
constructor(host: ReactiveElement, types: Optional<ReadonlyArray<EventType>>, handler: EventHandler<E>);
|
|
344
428
|
hostConnected(): void;
|
|
@@ -348,13 +432,13 @@ declare class OnEventController<E extends Event = Event> implements ReactiveCont
|
|
|
348
432
|
}
|
|
349
433
|
|
|
350
434
|
/**
|
|
351
|
-
*
|
|
435
|
+
* Represents options for the {@link useOnEvents} hook.
|
|
352
436
|
*
|
|
353
|
-
* @group
|
|
437
|
+
* @group Events
|
|
354
438
|
*/
|
|
355
439
|
interface UseOnEventsOptions<E extends Event = Event> {
|
|
356
440
|
/**
|
|
357
|
-
*
|
|
441
|
+
* The event handler function.
|
|
358
442
|
*/
|
|
359
443
|
handler: EventHandler<E>;
|
|
360
444
|
/**
|
|
@@ -363,15 +447,15 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
363
447
|
types?: Optional<EventType | ReadonlyArray<EventType>>;
|
|
364
448
|
}
|
|
365
449
|
/**
|
|
366
|
-
* Hook
|
|
450
|
+
* Hook that subscribes to events for the host element's lifetime.
|
|
367
451
|
*
|
|
368
|
-
* @group
|
|
452
|
+
* @group Events
|
|
369
453
|
*
|
|
370
|
-
* @param host -
|
|
371
|
-
* @param options -
|
|
372
|
-
* @param options.handler -
|
|
373
|
-
* @param options.types -
|
|
374
|
-
* @returns
|
|
454
|
+
* @param host - The host element.
|
|
455
|
+
* @param options - Event handling options.
|
|
456
|
+
* @param options.handler - Event handler function.
|
|
457
|
+
* @param options.types - Event types to listen for, if null or undefined, all events will be handled.
|
|
458
|
+
* @returns An instance of {@link OnEventController}.
|
|
375
459
|
*
|
|
376
460
|
* @example
|
|
377
461
|
* ```typescript
|
|
@@ -386,7 +470,7 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
386
470
|
* ```typescript
|
|
387
471
|
* class MyElement extends LitElement {
|
|
388
472
|
* private eventHandler = useOnEvents(this, {
|
|
389
|
-
* types: [
|
|
473
|
+
* types: ["MY_EVENT"],
|
|
390
474
|
* handler: (event) => console.log(event),
|
|
391
475
|
* });
|
|
392
476
|
* }
|
|
@@ -395,31 +479,33 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
395
479
|
declare function useOnEvents<E extends Event = Event>(host: ReactiveElement, { types, handler }: UseOnEventsOptions): OnEventController<E>;
|
|
396
480
|
|
|
397
481
|
/**
|
|
398
|
-
*
|
|
482
|
+
* Represents interface for the {@link onQuery} decorator.
|
|
399
483
|
*
|
|
400
|
-
*
|
|
484
|
+
* @remarks
|
|
485
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
401
486
|
*
|
|
402
|
-
* @group
|
|
487
|
+
* @group Queries
|
|
403
488
|
*/
|
|
404
489
|
interface OnQueryDecorator<D = unknown, R = unknown> {
|
|
405
490
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
|
|
406
491
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
407
492
|
}
|
|
408
493
|
/**
|
|
409
|
-
* Decorator
|
|
494
|
+
* Decorator for Lit element methods that handle a specific query.
|
|
410
495
|
*
|
|
411
|
-
*
|
|
496
|
+
* @remarks
|
|
497
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
412
498
|
*
|
|
413
|
-
* @group
|
|
499
|
+
* @group Queries
|
|
414
500
|
*
|
|
415
|
-
* @param type - the query
|
|
416
|
-
* @returns
|
|
501
|
+
* @param type - Unique identifier of the query to handle.
|
|
502
|
+
* @returns A method decorator function.
|
|
417
503
|
*
|
|
418
504
|
* @example
|
|
419
505
|
* ```typescript
|
|
420
506
|
* class MyElement extends LitElement {
|
|
421
507
|
* @onQuery("GET_USER_NAME")
|
|
422
|
-
*
|
|
508
|
+
* private onGetUserName(data: QueryData) {
|
|
423
509
|
* return "Alice";
|
|
424
510
|
* }
|
|
425
511
|
* }
|
|
@@ -430,10 +516,11 @@ declare function onQuery<D = unknown, R = unknown>(type: QueryType): OnQueryDeco
|
|
|
430
516
|
/**
|
|
431
517
|
* Reactive controller that registers a query handler on the {@link QueryBus} for the host element's lifetime.
|
|
432
518
|
*
|
|
519
|
+
* @remarks
|
|
433
520
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
434
|
-
*
|
|
521
|
+
* It automatically re-registers if the IoC container is updated.
|
|
435
522
|
*
|
|
436
|
-
* @group
|
|
523
|
+
* @group Queries
|
|
437
524
|
*/
|
|
438
525
|
declare class OnQueryController<D = unknown, R = unknown> implements ReactiveController {
|
|
439
526
|
private bus;
|
|
@@ -441,9 +528,9 @@ declare class OnQueryController<D = unknown, R = unknown> implements ReactiveCon
|
|
|
441
528
|
private readonly type;
|
|
442
529
|
private readonly handler;
|
|
443
530
|
/**
|
|
444
|
-
* @param host -
|
|
445
|
-
* @param type - the query
|
|
446
|
-
* @param handler -
|
|
531
|
+
* @param host - The host element.
|
|
532
|
+
* @param type - Unique identifier of the query to handle.
|
|
533
|
+
* @param handler - The query handler function.
|
|
447
534
|
*/
|
|
448
535
|
constructor(host: ReactiveElement, type: QueryType, handler: QueryHandler<D, R>);
|
|
449
536
|
hostConnected(): void;
|
|
@@ -453,9 +540,9 @@ declare class OnQueryController<D = unknown, R = unknown> implements ReactiveCon
|
|
|
453
540
|
}
|
|
454
541
|
|
|
455
542
|
/**
|
|
456
|
-
*
|
|
543
|
+
* Represents options for the {@link useOnQuery} hook.
|
|
457
544
|
*
|
|
458
|
-
* @group
|
|
545
|
+
* @group Queries
|
|
459
546
|
*/
|
|
460
547
|
interface UseOnQueryOptions<D = unknown, R = unknown> {
|
|
461
548
|
/**
|
|
@@ -468,15 +555,15 @@ interface UseOnQueryOptions<D = unknown, R = unknown> {
|
|
|
468
555
|
handler: QueryHandler<D, R>;
|
|
469
556
|
}
|
|
470
557
|
/**
|
|
471
|
-
*
|
|
558
|
+
* Hook that registers a query handler for the host element's lifetime.
|
|
472
559
|
*
|
|
473
|
-
* @group
|
|
560
|
+
* @group Queries
|
|
474
561
|
*
|
|
475
|
-
* @param host -
|
|
476
|
-
* @param options -
|
|
477
|
-
* @param options.type -
|
|
478
|
-
* @param options.handler -
|
|
479
|
-
* @returns
|
|
562
|
+
* @param host - The host element.
|
|
563
|
+
* @param options - Query handling options.
|
|
564
|
+
* @param options.type - The query type to handle.
|
|
565
|
+
* @param options.handler - The query handler function.
|
|
566
|
+
* @returns An instance of {@link OnQueryController}.
|
|
480
567
|
*
|
|
481
568
|
* @example
|
|
482
569
|
* ```typescript
|
|
@@ -491,280 +578,315 @@ interface UseOnQueryOptions<D = unknown, R = unknown> {
|
|
|
491
578
|
declare function useOnQuery<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnQueryOptions<D, R>): OnQueryController<D, R>;
|
|
492
579
|
|
|
493
580
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
* @group context
|
|
497
|
-
*/
|
|
498
|
-
interface IocContext {
|
|
499
|
-
/**
|
|
500
|
-
* The Inversify IoC container.
|
|
501
|
-
*/
|
|
502
|
-
readonly container: Container;
|
|
503
|
-
/**
|
|
504
|
-
* Revision counter for cache invalidation.
|
|
505
|
-
*/
|
|
506
|
-
readonly revision: number;
|
|
507
|
-
/**
|
|
508
|
-
* Function to force a revision update.
|
|
509
|
-
*/
|
|
510
|
-
readonly nextRevision: () => number;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Lit context for providing and consuming the IoC container.
|
|
581
|
+
* Lit context object for providing and consuming the container.
|
|
514
582
|
*
|
|
515
|
-
* @group
|
|
583
|
+
* @group Context
|
|
516
584
|
*/
|
|
517
585
|
declare const ContainerContext: {
|
|
518
|
-
__context__:
|
|
586
|
+
__context__: Container;
|
|
519
587
|
};
|
|
520
588
|
|
|
521
589
|
/**
|
|
522
|
-
*
|
|
590
|
+
* Represents options for the {@link ContainerProvider}.
|
|
523
591
|
*
|
|
524
|
-
* @
|
|
592
|
+
* @remarks
|
|
593
|
+
* Provide either an external `container` or managed creation `options`, but
|
|
594
|
+
* never both at the same time.
|
|
595
|
+
*
|
|
596
|
+
* @group Provision
|
|
525
597
|
*/
|
|
526
|
-
interface
|
|
598
|
+
interface ContainerProviderOptions {
|
|
527
599
|
/**
|
|
528
|
-
*
|
|
600
|
+
* External container instance to provide as-is.
|
|
601
|
+
*
|
|
602
|
+
* @remarks
|
|
603
|
+
* External containers are never activated, recreated, or disposed by this
|
|
604
|
+
* provider.
|
|
529
605
|
*/
|
|
530
|
-
container?: Container;
|
|
606
|
+
readonly container?: Container$1;
|
|
531
607
|
/**
|
|
532
|
-
*
|
|
608
|
+
* Managed container creation options.
|
|
609
|
+
*
|
|
610
|
+
* @remarks
|
|
611
|
+
* The managed container is created during provider construction without
|
|
612
|
+
* eager activation, activated when the host connects, disposed when it
|
|
613
|
+
* disconnects, and recreated on the next reconnect.
|
|
533
614
|
*/
|
|
534
|
-
|
|
615
|
+
readonly options?: CreateContainerOptions;
|
|
535
616
|
}
|
|
536
617
|
/**
|
|
537
|
-
*
|
|
618
|
+
* Provider that exposes an IoC container context to the host element and its children.
|
|
619
|
+
*
|
|
620
|
+
* @remarks
|
|
621
|
+
* The provider supports two modes:
|
|
538
622
|
*
|
|
539
|
-
*
|
|
623
|
+
* - External mode: `container` is an existing {@link Container}. The
|
|
624
|
+
* provider passes it through context and does not alter its lifecycle.
|
|
625
|
+
* - Managed mode: `options` is {@link CreateContainerOptions}. The provider
|
|
626
|
+
* creates a container during construction without eager activation,
|
|
627
|
+
* activates configured entries when the host connects, disposes the
|
|
628
|
+
* container when the host disconnects, and recreates it on reconnect.
|
|
540
629
|
*
|
|
541
|
-
* @group
|
|
630
|
+
* @group Provision
|
|
542
631
|
*/
|
|
543
|
-
declare class
|
|
544
|
-
|
|
545
|
-
protected
|
|
546
|
-
protected readonly seed?: AnyObject;
|
|
547
|
-
protected revision: number;
|
|
632
|
+
declare class ContainerProvider<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> extends ContextProvider<typeof ContainerContext, E> implements ReactiveController {
|
|
633
|
+
protected readonly options: Maybe<CreateContainerOptions>;
|
|
634
|
+
protected destroyed: boolean;
|
|
548
635
|
/**
|
|
549
|
-
*
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
* @returns current {@link IocContext} value served to child consumers
|
|
554
|
-
*/
|
|
555
|
-
get value(): IocContext;
|
|
556
|
-
/**
|
|
557
|
-
* @param host - the host element
|
|
558
|
-
* @param options - provisioning options
|
|
559
|
-
* @param options.container - optional existing container to use. If not provided, a new one will be created
|
|
560
|
-
* @param options.seed - optional seed data to apply to the container
|
|
636
|
+
* @param host - The host element.
|
|
637
|
+
* @param options - Provisioning options.
|
|
638
|
+
* @param options.container - External container instance to provide.
|
|
639
|
+
* @param options.options - Managed container creation options.
|
|
561
640
|
*/
|
|
562
|
-
constructor(host: E,
|
|
641
|
+
constructor(host: E, options: ContainerProviderOptions);
|
|
563
642
|
hostConnected(): void;
|
|
564
643
|
hostDisconnected(): void;
|
|
565
|
-
nextRevision(): number;
|
|
566
644
|
}
|
|
567
645
|
|
|
568
646
|
/**
|
|
569
|
-
*
|
|
647
|
+
* Represents options for the {@link SubContainerProvider}.
|
|
570
648
|
*
|
|
571
|
-
* @group
|
|
649
|
+
* @group Provision
|
|
572
650
|
*/
|
|
573
|
-
interface
|
|
574
|
-
|
|
575
|
-
|
|
651
|
+
interface SubContainerProviderOptions {
|
|
652
|
+
/**
|
|
653
|
+
* Managed child-container creation options.
|
|
654
|
+
*
|
|
655
|
+
* @remarks
|
|
656
|
+
* The child container is created from the current parent context when the
|
|
657
|
+
* host connects, destroyed when the host disconnects, and recreated when the
|
|
658
|
+
* parent context changes or the host reconnects.
|
|
659
|
+
*/
|
|
660
|
+
readonly options: {
|
|
661
|
+
/**
|
|
662
|
+
* List of service entries to bind to the container.
|
|
663
|
+
*/
|
|
664
|
+
readonly entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
|
|
665
|
+
/**
|
|
666
|
+
* List of service identifiers to activate (get from container) immediately after binding.
|
|
667
|
+
*/
|
|
668
|
+
readonly activate?: ReadonlyArray<ServiceIdentifier>;
|
|
669
|
+
/**
|
|
670
|
+
* Seed data to apply to the container before binding.
|
|
671
|
+
* Applied before entries are bound so that `@Inject(SEEDS_TOKEN)` works during activation.
|
|
672
|
+
*/
|
|
673
|
+
readonly seeds?: SeedEntries;
|
|
674
|
+
};
|
|
576
675
|
}
|
|
577
676
|
/**
|
|
578
|
-
*
|
|
677
|
+
* Provider that exposes a managed child container for the host element's lifetime.
|
|
579
678
|
*
|
|
580
|
-
* @
|
|
679
|
+
* @remarks
|
|
680
|
+
* The provider always owns a child container derived from the nearest parent
|
|
681
|
+
* {@link ContainerContext}. When connected, it creates a child container using
|
|
682
|
+
* the latest parent context, provides it to descendants, destroys it when the
|
|
683
|
+
* host disconnects, and replaces it whenever the parent container changes.
|
|
581
684
|
*
|
|
582
|
-
* @
|
|
583
|
-
* @param options.container - optional existing container to use, if not provided, a new one will be created
|
|
584
|
-
* @param options.seed - optional seed data to apply to the container
|
|
585
|
-
* @returns IOC provision controller instance
|
|
685
|
+
* @group Provision
|
|
586
686
|
*
|
|
587
687
|
* @example
|
|
588
688
|
* ```typescript
|
|
589
|
-
* class
|
|
590
|
-
*
|
|
591
|
-
*
|
|
689
|
+
* class MyComponent extends LitElement {
|
|
690
|
+
* private container = new SubContainerProvider(this, {
|
|
691
|
+
* options: {
|
|
692
|
+
* entries: [AuthService, UserService],
|
|
693
|
+
* activate: [AuthService],
|
|
694
|
+
* seeds: [[AuthService, { role: "admin" }]],
|
|
695
|
+
* },
|
|
696
|
+
* });
|
|
592
697
|
* }
|
|
593
698
|
* ```
|
|
594
699
|
*/
|
|
595
|
-
declare
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
type Callable<T> = () => T;
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Options for the {@link InjectablesProviderController}.
|
|
604
|
-
*
|
|
605
|
-
* @group provision
|
|
606
|
-
*/
|
|
607
|
-
interface InjectablesProviderControllerOptions {
|
|
700
|
+
declare class SubContainerProvider<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> extends ContextProvider<typeof ContainerContext, E> implements ReactiveController {
|
|
701
|
+
protected readonly consumer: ContextConsumer<typeof ContainerContext, E>;
|
|
702
|
+
protected readonly options: SubContainerProviderOptions["options"];
|
|
703
|
+
protected parent: Maybe<Container$1>;
|
|
704
|
+
protected destroyed: boolean;
|
|
608
705
|
/**
|
|
609
|
-
*
|
|
610
|
-
|
|
611
|
-
entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
|
|
612
|
-
/**
|
|
613
|
-
* Target IoC context to bind injectables into.
|
|
614
|
-
* If not provided, uses the context from the nearest provider.
|
|
615
|
-
* Accepts a static {@link IocContext} reference or a resolver function.
|
|
706
|
+
* @param host - The host element.
|
|
707
|
+
* @param options - Provisioning options, including child entries, eager activations, and seeds.
|
|
616
708
|
*/
|
|
617
|
-
|
|
709
|
+
constructor(host: E, options: SubContainerProviderOptions);
|
|
710
|
+
hostConnected(): void;
|
|
711
|
+
hostDisconnected(): void;
|
|
618
712
|
/**
|
|
619
|
-
*
|
|
713
|
+
* Replaces the currently provided child container with a new one derived
|
|
714
|
+
* from the latest parent context.
|
|
620
715
|
*/
|
|
621
|
-
|
|
716
|
+
protected createContainer(): void;
|
|
622
717
|
/**
|
|
623
|
-
*
|
|
624
|
-
* Applied before entries are bound so that `@Inject(SEEDS_TOKEN)` works during activation.
|
|
718
|
+
* Destroys the currently provided child container.
|
|
625
719
|
*/
|
|
626
|
-
|
|
720
|
+
protected destroyContainer(): void;
|
|
627
721
|
}
|
|
722
|
+
|
|
628
723
|
/**
|
|
629
|
-
*
|
|
630
|
-
* and unbinds them when the host disconnects.
|
|
724
|
+
* Represents interface for the {@link containerProvide} decorator.
|
|
631
725
|
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
* works during service activation.
|
|
726
|
+
* @remarks
|
|
727
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
635
728
|
*
|
|
636
|
-
* @group
|
|
729
|
+
* @group Provision
|
|
730
|
+
*/
|
|
731
|
+
interface ContainerProviderDecorator<E extends ReactiveElement = ReactiveElement> {
|
|
732
|
+
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends ContainerProvider<E>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
|
|
733
|
+
<K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, ContainerProvider<E>>;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Decorator that provides an IoC container to child components.
|
|
737
|
+
*
|
|
738
|
+
* @remarks
|
|
739
|
+
* The container is provided via Lit context.
|
|
740
|
+
*
|
|
741
|
+
* - Pass `container` to expose an external container without taking
|
|
742
|
+
* ownership.
|
|
743
|
+
* - Pass `options` to create a managed container during construction,
|
|
744
|
+
* activate configured entries on connect, destroy it on disconnect, and
|
|
745
|
+
* recreate it on reconnect.
|
|
746
|
+
*
|
|
747
|
+
* @group Provision
|
|
748
|
+
*
|
|
749
|
+
* @param options - Provisioning options.
|
|
750
|
+
* @param options.container - External container instance to provide.
|
|
751
|
+
* @param options.options - Managed container creation options.
|
|
752
|
+
* @returns An instance of {@link ContainerProviderDecorator}.
|
|
637
753
|
*
|
|
638
754
|
* @example
|
|
639
755
|
* ```typescript
|
|
640
|
-
* class
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
756
|
+
* class MyRootElement extends LitElement {
|
|
757
|
+
* @containerProvide({
|
|
758
|
+
* options: {
|
|
759
|
+
* seed: { someData: "value" },
|
|
760
|
+
* entries: [LoggerService],
|
|
761
|
+
* },
|
|
762
|
+
* })
|
|
763
|
+
* private containerProvider!: ContainerProvider;
|
|
764
|
+
* }
|
|
765
|
+
* ```
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* class MyRootElement extends LitElement {
|
|
770
|
+
* @containerProvide({ container: container })
|
|
771
|
+
* private containerProvider!: ContainerProvider;
|
|
646
772
|
* }
|
|
647
773
|
* ```
|
|
648
774
|
*/
|
|
649
|
-
declare
|
|
650
|
-
private readonly host;
|
|
651
|
-
protected readonly consumer?: ContextConsumer<typeof ContainerContext, E>;
|
|
652
|
-
private readonly entries;
|
|
653
|
-
private readonly activate;
|
|
654
|
-
private readonly seeds;
|
|
655
|
-
private readonly into;
|
|
656
|
-
/**
|
|
657
|
-
* Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
|
|
658
|
-
*/
|
|
659
|
-
private boundContext;
|
|
660
|
-
/**
|
|
661
|
-
* @param host - the host element
|
|
662
|
-
* @param options - provisioning options
|
|
663
|
-
* @param options.entries - list of service entries to bind to the container
|
|
664
|
-
* @param options.into - target IoC context; if omitted, uses the nearest provider context
|
|
665
|
-
* @param options.activate - list of service identifiers to activate immediately after binding
|
|
666
|
-
* @param options.seeds - seed data applied before binding
|
|
667
|
-
*/
|
|
668
|
-
constructor(host: E, options: InjectablesProviderControllerOptions);
|
|
669
|
-
hostConnected(): void;
|
|
670
|
-
hostDisconnected(): void;
|
|
671
|
-
private bind;
|
|
672
|
-
private unbind;
|
|
673
|
-
}
|
|
775
|
+
declare function containerProvide<E extends ReactiveElement>(options: ContainerProviderOptions): ContainerProviderDecorator<E>;
|
|
674
776
|
|
|
675
777
|
/**
|
|
676
|
-
*
|
|
778
|
+
* Represents type for the {@link subContainerProvide} decorator.
|
|
677
779
|
*
|
|
678
|
-
*
|
|
780
|
+
* @remarks
|
|
781
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
679
782
|
*
|
|
680
|
-
* @group
|
|
783
|
+
* @group Provision
|
|
681
784
|
*/
|
|
682
|
-
interface
|
|
683
|
-
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends
|
|
684
|
-
<K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K,
|
|
785
|
+
interface SubContainerProviderDecorator<T extends ReactiveElement = ReactiveElement> {
|
|
786
|
+
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends SubContainerProvider<T>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
|
|
787
|
+
<K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, SubContainerProvider<T>>;
|
|
685
788
|
}
|
|
686
789
|
/**
|
|
687
|
-
* Decorator that
|
|
790
|
+
* Decorator that provides a managed child container derived from the nearest
|
|
791
|
+
* parent container context.
|
|
688
792
|
*
|
|
689
|
-
*
|
|
690
|
-
* The
|
|
793
|
+
* @remarks
|
|
794
|
+
* The child container is created from the current parent context when the host
|
|
795
|
+
* connects, destroyed when it disconnects, and recreated when the parent
|
|
796
|
+
* container changes.
|
|
691
797
|
*
|
|
692
|
-
* @group
|
|
798
|
+
* @group Provision
|
|
693
799
|
*
|
|
694
|
-
* @param options -
|
|
695
|
-
* @
|
|
800
|
+
* @param options - Provisioning options.
|
|
801
|
+
* @param options.options - Child-container creation options.
|
|
802
|
+
* @returns An instance of {@link SubContainerProviderDecorator}.
|
|
696
803
|
*
|
|
697
804
|
* @example
|
|
698
805
|
* ```typescript
|
|
699
806
|
* class MyComponent extends LitElement {
|
|
700
|
-
* @
|
|
701
|
-
*
|
|
807
|
+
* @subContainerProvide({
|
|
808
|
+
* options: {
|
|
809
|
+
* entries: [AuthService, UserService],
|
|
810
|
+
* activate: [AuthService],
|
|
811
|
+
* },
|
|
812
|
+
* })
|
|
813
|
+
* public containerProvider!: SubContainerProvider<MyComponent>;
|
|
702
814
|
* }
|
|
703
815
|
* ```
|
|
704
816
|
*/
|
|
705
|
-
declare function
|
|
817
|
+
declare function subContainerProvide<E extends ReactiveElement = ReactiveElement>(options: SubContainerProviderOptions): SubContainerProviderDecorator<E>;
|
|
706
818
|
|
|
707
819
|
/**
|
|
708
|
-
*
|
|
820
|
+
* Represents options for the {@link useContainerProvision} hook.
|
|
821
|
+
*
|
|
822
|
+
* @group Provision
|
|
823
|
+
*/
|
|
824
|
+
type UseContainerProvisionOptions = ContainerProviderOptions;
|
|
825
|
+
/**
|
|
826
|
+
* Hook that provides a container to the host element and its children.
|
|
709
827
|
*
|
|
710
|
-
*
|
|
828
|
+
* @remarks
|
|
829
|
+
* Pass `container` to expose an external `Container` without taking
|
|
830
|
+
* ownership. Pass `options` to create a managed container during
|
|
831
|
+
* construction, activate configured entries on connect, destroy it on
|
|
832
|
+
* disconnect, and recreate it on reconnect.
|
|
711
833
|
*
|
|
712
|
-
* @group
|
|
834
|
+
* @group Provision
|
|
713
835
|
*
|
|
714
|
-
* @param host -
|
|
715
|
-
* @param options -
|
|
716
|
-
* @param options.
|
|
717
|
-
* @param options.
|
|
718
|
-
* @
|
|
719
|
-
* @param options.seeds - seed data applied before binding
|
|
720
|
-
* @returns the controller instance
|
|
836
|
+
* @param host - The host element.
|
|
837
|
+
* @param options - Provisioning options.
|
|
838
|
+
* @param options.container - External container instance to provide.
|
|
839
|
+
* @param options.options - Managed container creation options.
|
|
840
|
+
* @returns An instance of {@link ContainerProvider}.
|
|
721
841
|
*
|
|
722
842
|
* @example
|
|
723
843
|
* ```typescript
|
|
724
|
-
* class
|
|
725
|
-
* private
|
|
726
|
-
*
|
|
727
|
-
*
|
|
844
|
+
* class MyRootElement extends LitElement {
|
|
845
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, {
|
|
846
|
+
* options: {
|
|
847
|
+
* entries: [LoggerService],
|
|
848
|
+
* activate: [LoggerService],
|
|
849
|
+
* },
|
|
728
850
|
* });
|
|
729
851
|
* }
|
|
730
852
|
* ```
|
|
853
|
+
*
|
|
854
|
+
* @example
|
|
855
|
+
* ```typescript
|
|
856
|
+
* class MyRootElement extends LitElement {
|
|
857
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
|
|
858
|
+
* }
|
|
859
|
+
* ```
|
|
731
860
|
*/
|
|
732
|
-
declare function
|
|
861
|
+
declare function useContainerProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, options: UseContainerProvisionOptions): ContainerProvider<E>;
|
|
733
862
|
|
|
734
863
|
/**
|
|
735
|
-
*
|
|
864
|
+
* Hook that provides a managed child container for the host element's lifetime.
|
|
736
865
|
*
|
|
737
|
-
* @
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
* Optional existing container to use.
|
|
742
|
-
*/
|
|
743
|
-
container?: Container;
|
|
744
|
-
/**
|
|
745
|
-
* Optional seed data to apply to the container.
|
|
746
|
-
*/
|
|
747
|
-
seed?: AnyObject;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Hook (controller) to provide an IoC container to the host element and its children.
|
|
866
|
+
* @remarks
|
|
867
|
+
* The child container is derived from the current parent
|
|
868
|
+
* {@link ContainerContext}, recreated when that parent context changes, and
|
|
869
|
+
* destroyed when the host disconnects.
|
|
751
870
|
*
|
|
752
|
-
* @group
|
|
871
|
+
* @group Provision
|
|
753
872
|
*
|
|
754
|
-
* @param host -
|
|
755
|
-
* @param options -
|
|
756
|
-
* @param options.
|
|
757
|
-
* @
|
|
758
|
-
* @returns ioc provision controller instance
|
|
873
|
+
* @param host - The host element.
|
|
874
|
+
* @param options - Provisioning options.
|
|
875
|
+
* @param options.options - Child-container creation options.
|
|
876
|
+
* @returns An instance of {@link SubContainerProvider}.
|
|
759
877
|
*
|
|
760
878
|
* @example
|
|
761
879
|
* ```typescript
|
|
762
|
-
* class
|
|
763
|
-
* private
|
|
880
|
+
* class MyComponent extends LitElement {
|
|
881
|
+
* private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
|
|
882
|
+
* options: {
|
|
883
|
+
* entries: [AuthService, UserService],
|
|
884
|
+
* },
|
|
885
|
+
* });
|
|
764
886
|
* }
|
|
765
887
|
* ```
|
|
766
888
|
*/
|
|
767
|
-
declare function
|
|
889
|
+
declare function useSubContainerProvider<E extends ReactiveControllerHost & HTMLElement>(host: E, options: SubContainerProviderOptions): SubContainerProvider<E>;
|
|
768
890
|
|
|
769
|
-
export { ContainerContext,
|
|
770
|
-
export type {
|
|
891
|
+
export { ContainerContext, ContainerProvider, OnCommandController, OnEventController, OnQueryController, SubContainerProvider, containerProvide, injection, onCommand, onEvent, onQuery, subContainerProvide, useContainer, useContainerProvision, useInjection, useOnCommand, useOnEvents, useOnQuery, useScope, useSubContainerProvider };
|
|
892
|
+
export type { ContainerProviderDecorator, ContainerProviderOptions, InjectionDecorator, InjectionOptions, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, SubContainerProviderDecorator, SubContainerProviderOptions, UseContainerProvisionOptions, UseContainerValue, UseInjectionOptions, UseInjectionValue, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions, UseScopeValue };
|