@wirestate/lit 0.6.1 → 0.7.0-experimental.1
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 +10 -1
- package/README.md +44 -44
- package/cjs/development/index.js +136 -129
- 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 +7 -6
- 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 +6 -6
- package/esm/development/consumption/injection.js.map +1 -1
- package/esm/development/consumption/use-injection.js +7 -7
- package/esm/development/consumption/use-injection.js.map +1 -1
- package/esm/development/context/ioc-context.js +6 -6
- package/esm/development/context/ioc-context.js.map +1 -1
- package/esm/development/events/on-event-controller.js +10 -8
- 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 +1 -1
- package/esm/development/provision/injectables-provide.js +5 -5
- package/esm/development/provision/injectables-provide.js.map +1 -1
- package/esm/development/provision/injectables-provider-controller.js +14 -14
- package/esm/development/provision/injectables-provider-controller.js.map +1 -1
- package/esm/development/provision/ioc-provide.js +10 -7
- package/esm/development/provision/ioc-provide.js.map +1 -1
- package/esm/development/provision/ioc-provider-controller.js +13 -10
- package/esm/development/provision/ioc-provider-controller.js.map +1 -1
- package/esm/development/provision/use-injectables-provider.js +5 -11
- package/esm/development/provision/use-injectables-provider.js.map +1 -1
- package/esm/development/provision/use-ioc-provision.js +6 -8
- package/esm/development/provision/use-ioc-provision.js.map +1 -1
- package/esm/development/queries/on-query-controller.js +8 -7
- 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-injection.js +1 -1
- package/esm/production/consumption/use-injection.js.map +1 -1
- package/esm/production/context/ioc-context.js +1 -1
- package/esm/production/context/ioc-context.js.map +1 -1
- 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/injectables-provide.js.map +1 -1
- package/esm/production/provision/injectables-provider-controller.js +1 -1
- package/esm/production/provision/injectables-provider-controller.js.map +1 -1
- package/esm/production/provision/ioc-provide.js.map +1 -1
- package/esm/production/provision/ioc-provider-controller.js +1 -1
- package/esm/production/provision/ioc-provider-controller.js.map +1 -1
- package/esm/production/provision/use-injectables-provider.js.map +1 -1
- package/esm/production/provision/use-ioc-provision.js.map +1 -1
- 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 +199 -172
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -3,27 +3,27 @@ import { ServiceIdentifier, CommandType, CommandHandler, Event, EventType, Event
|
|
|
3
3
|
import { ContextProvider, ContextConsumer } from '@lit/context';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Any object with string or symbol keys.
|
|
7
7
|
*
|
|
8
|
-
* @group
|
|
8
|
+
* @group Types
|
|
9
9
|
*/
|
|
10
10
|
type AnyObject = Record<string | symbol, any>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Type that can be null.
|
|
13
13
|
*
|
|
14
|
-
* @group
|
|
14
|
+
* @group Types
|
|
15
15
|
*/
|
|
16
16
|
type Optional<T> = T | null;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Value or a promise of that value.
|
|
19
19
|
*
|
|
20
|
-
* @group
|
|
20
|
+
* @group Types
|
|
21
21
|
*/
|
|
22
22
|
type MaybePromise<T> = T | Promise<T>;
|
|
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
54
|
*
|
|
55
|
-
* @
|
|
55
|
+
* @remarks
|
|
56
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
57
|
+
*
|
|
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,21 @@ interface InjectionOptions<T> {
|
|
|
111
115
|
declare function injection<T>(optionsOrInjectionId: InjectionOptions<T> | ServiceIdentifier<T>): InjectionDecorator<T>;
|
|
112
116
|
|
|
113
117
|
/**
|
|
114
|
-
*
|
|
118
|
+
* Represents options for the {@link useInjection} hook.
|
|
115
119
|
*
|
|
116
|
-
* @group
|
|
120
|
+
* @group Consumption
|
|
117
121
|
*/
|
|
118
122
|
interface UseInjectionOptions<T> {
|
|
119
123
|
/**
|
|
124
|
+
* Whether to subscribe to container changes.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
120
127
|
* If true, the service will be fetched only once when the controller is created.
|
|
121
|
-
*
|
|
128
|
+
* Defaults to false.
|
|
122
129
|
*/
|
|
123
130
|
once?: boolean;
|
|
124
131
|
/**
|
|
125
|
-
* Initial value
|
|
132
|
+
* Initial value before the service is fetched.
|
|
126
133
|
*/
|
|
127
134
|
value?: Optional<T>;
|
|
128
135
|
/**
|
|
@@ -131,9 +138,9 @@ interface UseInjectionOptions<T> {
|
|
|
131
138
|
injectionId: ServiceIdentifier<T>;
|
|
132
139
|
}
|
|
133
140
|
/**
|
|
134
|
-
*
|
|
141
|
+
* Represents result of the {@link useInjection} hook.
|
|
135
142
|
*
|
|
136
|
-
* @group
|
|
143
|
+
* @group Consumption
|
|
137
144
|
*/
|
|
138
145
|
interface UseInjectionValue<T> {
|
|
139
146
|
/**
|
|
@@ -146,13 +153,13 @@ interface UseInjectionValue<T> {
|
|
|
146
153
|
value: T;
|
|
147
154
|
}
|
|
148
155
|
/**
|
|
149
|
-
* Hook (controller) to inject a service from the IoC container
|
|
156
|
+
* Hook (controller) to inject a service from the IoC container.
|
|
150
157
|
*
|
|
151
|
-
* @group
|
|
158
|
+
* @group Consumption
|
|
152
159
|
*
|
|
153
|
-
* @param host -
|
|
154
|
-
* @param optionsOrInjectionId -
|
|
155
|
-
* @returns
|
|
160
|
+
* @param host - The host element.
|
|
161
|
+
* @param optionsOrInjectionId - Injection options or service identifier.
|
|
162
|
+
* @returns An instance of {@link UseInjectionValue}.
|
|
156
163
|
*
|
|
157
164
|
* @example
|
|
158
165
|
* ```typescript
|
|
@@ -179,31 +186,33 @@ interface UseInjectionValue<T> {
|
|
|
179
186
|
declare function useInjection<T extends object, E extends ReactiveControllerHost & HTMLElement>(host: E, optionsOrInjectionId: UseInjectionOptions<T> | ServiceIdentifier<T>): UseInjectionValue<T>;
|
|
180
187
|
|
|
181
188
|
/**
|
|
182
|
-
*
|
|
189
|
+
* Represents interface for the {@link onCommand} decorator.
|
|
183
190
|
*
|
|
184
|
-
*
|
|
191
|
+
* @remarks
|
|
192
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
185
193
|
*
|
|
186
|
-
* @group
|
|
194
|
+
* @group Commands
|
|
187
195
|
*/
|
|
188
196
|
interface OnCommandDecorator<D = unknown, R = unknown> {
|
|
189
197
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
|
|
190
198
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
191
199
|
}
|
|
192
200
|
/**
|
|
193
|
-
* Decorator
|
|
201
|
+
* Decorator for Lit element methods that handle a specific command.
|
|
194
202
|
*
|
|
195
|
-
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
196
205
|
*
|
|
197
|
-
* @group
|
|
206
|
+
* @group Commands
|
|
198
207
|
*
|
|
199
|
-
* @param type - the command
|
|
200
|
-
* @returns
|
|
208
|
+
* @param type - Unique identifier of the command to handle.
|
|
209
|
+
* @returns A method decorator function.
|
|
201
210
|
*
|
|
202
211
|
* @example
|
|
203
212
|
* ```typescript
|
|
204
213
|
* class MyElement extends LitElement {
|
|
205
214
|
* @onCommand("SAVE")
|
|
206
|
-
* private
|
|
215
|
+
* private onSave(data: SomeData): void {
|
|
207
216
|
* // handle command
|
|
208
217
|
* }
|
|
209
218
|
* }
|
|
@@ -212,12 +221,13 @@ interface OnCommandDecorator<D = unknown, R = unknown> {
|
|
|
212
221
|
declare function onCommand<D = unknown, R = unknown>(type: CommandType): OnCommandDecorator<D, R>;
|
|
213
222
|
|
|
214
223
|
/**
|
|
215
|
-
*
|
|
224
|
+
* Controller that registers a command handler for the host element's lifetime.
|
|
216
225
|
*
|
|
226
|
+
* @remarks
|
|
217
227
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
218
|
-
*
|
|
228
|
+
* It automatically re-registers if the IoC container is updated.
|
|
219
229
|
*
|
|
220
|
-
* @group
|
|
230
|
+
* @group Commands
|
|
221
231
|
*/
|
|
222
232
|
declare class OnCommandController<D = unknown, R = unknown> implements ReactiveController {
|
|
223
233
|
private bus;
|
|
@@ -226,7 +236,7 @@ declare class OnCommandController<D = unknown, R = unknown> implements ReactiveC
|
|
|
226
236
|
private readonly handler;
|
|
227
237
|
/**
|
|
228
238
|
* @param host - The host element.
|
|
229
|
-
* @param type -
|
|
239
|
+
* @param type - Unique identifier of the command to handle.
|
|
230
240
|
* @param handler - The command handler function.
|
|
231
241
|
*/
|
|
232
242
|
constructor(host: ReactiveElement, type: CommandType, handler: CommandHandler<D, R>);
|
|
@@ -237,9 +247,9 @@ declare class OnCommandController<D = unknown, R = unknown> implements ReactiveC
|
|
|
237
247
|
}
|
|
238
248
|
|
|
239
249
|
/**
|
|
240
|
-
*
|
|
250
|
+
* Represents options for the {@link useOnCommand} hook.
|
|
241
251
|
*
|
|
242
|
-
* @group
|
|
252
|
+
* @group Commands
|
|
243
253
|
*/
|
|
244
254
|
interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
245
255
|
/**
|
|
@@ -252,15 +262,15 @@ interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
|
252
262
|
handler: CommandHandler<D, R>;
|
|
253
263
|
}
|
|
254
264
|
/**
|
|
255
|
-
*
|
|
265
|
+
* Hook that registers a command handler for the host element's lifetime.
|
|
256
266
|
*
|
|
257
|
-
* @group
|
|
267
|
+
* @group Commands
|
|
258
268
|
*
|
|
259
|
-
* @param host -
|
|
260
|
-
* @param options -
|
|
261
|
-
* @param options.type -
|
|
262
|
-
* @param options.handler -
|
|
263
|
-
* @returns
|
|
269
|
+
* @param host - The host element.
|
|
270
|
+
* @param options - Command handling options.
|
|
271
|
+
* @param options.type - The command type to listen for.
|
|
272
|
+
* @param options.handler - The command handler function.
|
|
273
|
+
* @returns The command controller instance.
|
|
264
274
|
*
|
|
265
275
|
* @example
|
|
266
276
|
* ```typescript
|
|
@@ -275,28 +285,34 @@ interface UseOnCommandOptions<D = unknown, R = unknown> {
|
|
|
275
285
|
declare function useOnCommand<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnCommandOptions<D, R>): OnCommandController<D, R>;
|
|
276
286
|
|
|
277
287
|
/**
|
|
278
|
-
*
|
|
288
|
+
* Represents type definition for the on-event decorator.
|
|
289
|
+
*
|
|
290
|
+
* @remarks
|
|
291
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
279
292
|
*
|
|
280
|
-
* @group
|
|
293
|
+
* @group Events
|
|
281
294
|
*/
|
|
282
295
|
interface OnEventDecorator<E extends Event = Event> {
|
|
283
296
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, event: E) => void, context: ClassMethodDecoratorContext<This>): void;
|
|
284
297
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
285
298
|
}
|
|
286
299
|
/**
|
|
287
|
-
* Decorator
|
|
300
|
+
* Decorator for Lit element methods that handle events from the event bus.
|
|
288
301
|
*
|
|
289
|
-
* @
|
|
302
|
+
* @remarks
|
|
303
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
304
|
+
*
|
|
305
|
+
* @group Events
|
|
290
306
|
*
|
|
291
307
|
* @param types - Event types to listen for. If omitted, all events will be handled.
|
|
292
|
-
* @returns
|
|
308
|
+
* @returns A method decorator function.
|
|
293
309
|
*
|
|
294
310
|
* @example
|
|
295
311
|
* ```typescript
|
|
296
312
|
* class MyElement extends LitElement {
|
|
297
313
|
* @onEvent()
|
|
298
314
|
* private onMyEvent(event: Event) {
|
|
299
|
-
* console.log(
|
|
315
|
+
* console.log("Event received:", event);
|
|
300
316
|
* }
|
|
301
317
|
* }
|
|
302
318
|
* ```
|
|
@@ -304,9 +320,9 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
304
320
|
* @example
|
|
305
321
|
* ```typescript
|
|
306
322
|
* class MyElement extends LitElement {
|
|
307
|
-
* @onEvent(
|
|
323
|
+
* @onEvent("MY_EVENT_TYPE")
|
|
308
324
|
* private onMyEvent(event: MyEvent) {
|
|
309
|
-
* console.log(
|
|
325
|
+
* console.log("Event received:", event);
|
|
310
326
|
* }
|
|
311
327
|
* }
|
|
312
328
|
* ```
|
|
@@ -314,9 +330,9 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
314
330
|
* @example
|
|
315
331
|
* ```typescript
|
|
316
332
|
* class MyElement extends LitElement {
|
|
317
|
-
* @onEvent([
|
|
333
|
+
* @onEvent(["MY_EVENT_TYPE_1", "MY_EVENT_TYPE_2"])
|
|
318
334
|
* private onMyEvent(event: Event) {
|
|
319
|
-
* console.log(
|
|
335
|
+
* console.log("Event received:", event);
|
|
320
336
|
* }
|
|
321
337
|
* }
|
|
322
338
|
* ```
|
|
@@ -324,11 +340,13 @@ interface OnEventDecorator<E extends Event = Event> {
|
|
|
324
340
|
declare function onEvent<E extends Event = Event>(types?: EventType | ReadonlyArray<EventType>): OnEventDecorator<E>;
|
|
325
341
|
|
|
326
342
|
/**
|
|
327
|
-
* Controller that subscribes to events
|
|
343
|
+
* Controller that subscribes to events for the host element's lifetime.
|
|
328
344
|
*
|
|
329
|
-
*
|
|
345
|
+
* @remarks
|
|
346
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
347
|
+
* It automatically re-subscribes if the IoC container is updated.
|
|
330
348
|
*
|
|
331
|
-
* @group
|
|
349
|
+
* @group Events
|
|
332
350
|
*/
|
|
333
351
|
declare class OnEventController<E extends Event = Event> implements ReactiveController {
|
|
334
352
|
private bus;
|
|
@@ -336,9 +354,9 @@ declare class OnEventController<E extends Event = Event> implements ReactiveCont
|
|
|
336
354
|
private readonly types;
|
|
337
355
|
private readonly handler;
|
|
338
356
|
/**
|
|
339
|
-
* @param host -
|
|
340
|
-
* @param types -
|
|
341
|
-
* @param handler -
|
|
357
|
+
* @param host - The host element.
|
|
358
|
+
* @param types - Event types to listen for. If null, all events will be handled.
|
|
359
|
+
* @param handler - The event handler function.
|
|
342
360
|
*/
|
|
343
361
|
constructor(host: ReactiveElement, types: Optional<ReadonlyArray<EventType>>, handler: EventHandler<E>);
|
|
344
362
|
hostConnected(): void;
|
|
@@ -348,13 +366,13 @@ declare class OnEventController<E extends Event = Event> implements ReactiveCont
|
|
|
348
366
|
}
|
|
349
367
|
|
|
350
368
|
/**
|
|
351
|
-
*
|
|
369
|
+
* Represents options for the {@link useOnEvents} hook.
|
|
352
370
|
*
|
|
353
|
-
* @group
|
|
371
|
+
* @group Events
|
|
354
372
|
*/
|
|
355
373
|
interface UseOnEventsOptions<E extends Event = Event> {
|
|
356
374
|
/**
|
|
357
|
-
*
|
|
375
|
+
* The event handler function.
|
|
358
376
|
*/
|
|
359
377
|
handler: EventHandler<E>;
|
|
360
378
|
/**
|
|
@@ -363,15 +381,15 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
363
381
|
types?: Optional<EventType | ReadonlyArray<EventType>>;
|
|
364
382
|
}
|
|
365
383
|
/**
|
|
366
|
-
* Hook
|
|
384
|
+
* Hook that subscribes to events for the host element's lifetime.
|
|
367
385
|
*
|
|
368
|
-
* @group
|
|
386
|
+
* @group Events
|
|
369
387
|
*
|
|
370
|
-
* @param host -
|
|
371
|
-
* @param options -
|
|
372
|
-
* @param options.handler -
|
|
373
|
-
* @param options.types -
|
|
374
|
-
* @returns
|
|
388
|
+
* @param host - The host element.
|
|
389
|
+
* @param options - Event handling options.
|
|
390
|
+
* @param options.handler - Event handler function.
|
|
391
|
+
* @param options.types - Event types to listen for, if null or undefined, all events will be handled.
|
|
392
|
+
* @returns An instance of {@link OnEventController}.
|
|
375
393
|
*
|
|
376
394
|
* @example
|
|
377
395
|
* ```typescript
|
|
@@ -386,7 +404,7 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
386
404
|
* ```typescript
|
|
387
405
|
* class MyElement extends LitElement {
|
|
388
406
|
* private eventHandler = useOnEvents(this, {
|
|
389
|
-
* types: [
|
|
407
|
+
* types: ["MY_EVENT"],
|
|
390
408
|
* handler: (event) => console.log(event),
|
|
391
409
|
* });
|
|
392
410
|
* }
|
|
@@ -395,31 +413,33 @@ interface UseOnEventsOptions<E extends Event = Event> {
|
|
|
395
413
|
declare function useOnEvents<E extends Event = Event>(host: ReactiveElement, { types, handler }: UseOnEventsOptions): OnEventController<E>;
|
|
396
414
|
|
|
397
415
|
/**
|
|
398
|
-
*
|
|
416
|
+
* Represents interface for the {@link onQuery} decorator.
|
|
399
417
|
*
|
|
400
|
-
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
401
420
|
*
|
|
402
|
-
* @group
|
|
421
|
+
* @group Queries
|
|
403
422
|
*/
|
|
404
423
|
interface OnQueryDecorator<D = unknown, R = unknown> {
|
|
405
424
|
<This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
|
|
406
425
|
(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
407
426
|
}
|
|
408
427
|
/**
|
|
409
|
-
* Decorator
|
|
428
|
+
* Decorator for Lit element methods that handle a specific query.
|
|
410
429
|
*
|
|
411
|
-
*
|
|
430
|
+
* @remarks
|
|
431
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
412
432
|
*
|
|
413
|
-
* @group
|
|
433
|
+
* @group Queries
|
|
414
434
|
*
|
|
415
|
-
* @param type - the query
|
|
416
|
-
* @returns
|
|
435
|
+
* @param type - Unique identifier of the query to handle.
|
|
436
|
+
* @returns A method decorator function.
|
|
417
437
|
*
|
|
418
438
|
* @example
|
|
419
439
|
* ```typescript
|
|
420
440
|
* class MyElement extends LitElement {
|
|
421
441
|
* @onQuery("GET_USER_NAME")
|
|
422
|
-
*
|
|
442
|
+
* private onGetUserName(data: QueryData) {
|
|
423
443
|
* return "Alice";
|
|
424
444
|
* }
|
|
425
445
|
* }
|
|
@@ -430,10 +450,11 @@ declare function onQuery<D = unknown, R = unknown>(type: QueryType): OnQueryDeco
|
|
|
430
450
|
/**
|
|
431
451
|
* Reactive controller that registers a query handler on the {@link QueryBus} for the host element's lifetime.
|
|
432
452
|
*
|
|
453
|
+
* @remarks
|
|
433
454
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
434
|
-
*
|
|
455
|
+
* It automatically re-registers if the IoC container is updated.
|
|
435
456
|
*
|
|
436
|
-
* @group
|
|
457
|
+
* @group Queries
|
|
437
458
|
*/
|
|
438
459
|
declare class OnQueryController<D = unknown, R = unknown> implements ReactiveController {
|
|
439
460
|
private bus;
|
|
@@ -441,9 +462,9 @@ declare class OnQueryController<D = unknown, R = unknown> implements ReactiveCon
|
|
|
441
462
|
private readonly type;
|
|
442
463
|
private readonly handler;
|
|
443
464
|
/**
|
|
444
|
-
* @param host -
|
|
445
|
-
* @param type - the query
|
|
446
|
-
* @param handler -
|
|
465
|
+
* @param host - The host element.
|
|
466
|
+
* @param type - Unique identifier of the query to handle.
|
|
467
|
+
* @param handler - The query handler function.
|
|
447
468
|
*/
|
|
448
469
|
constructor(host: ReactiveElement, type: QueryType, handler: QueryHandler<D, R>);
|
|
449
470
|
hostConnected(): void;
|
|
@@ -453,9 +474,9 @@ declare class OnQueryController<D = unknown, R = unknown> implements ReactiveCon
|
|
|
453
474
|
}
|
|
454
475
|
|
|
455
476
|
/**
|
|
456
|
-
*
|
|
477
|
+
* Represents options for the {@link useOnQuery} hook.
|
|
457
478
|
*
|
|
458
|
-
* @group
|
|
479
|
+
* @group Queries
|
|
459
480
|
*/
|
|
460
481
|
interface UseOnQueryOptions<D = unknown, R = unknown> {
|
|
461
482
|
/**
|
|
@@ -468,15 +489,15 @@ interface UseOnQueryOptions<D = unknown, R = unknown> {
|
|
|
468
489
|
handler: QueryHandler<D, R>;
|
|
469
490
|
}
|
|
470
491
|
/**
|
|
471
|
-
*
|
|
492
|
+
* Hook that registers a query handler for the host element's lifetime.
|
|
472
493
|
*
|
|
473
|
-
* @group
|
|
494
|
+
* @group Queries
|
|
474
495
|
*
|
|
475
|
-
* @param host -
|
|
476
|
-
* @param options -
|
|
477
|
-
* @param options.type -
|
|
478
|
-
* @param options.handler -
|
|
479
|
-
* @returns
|
|
496
|
+
* @param host - The host element.
|
|
497
|
+
* @param options - Query handling options.
|
|
498
|
+
* @param options.type - The query type to handle.
|
|
499
|
+
* @param options.handler - The query handler function.
|
|
500
|
+
* @returns An instance of {@link OnQueryController}.
|
|
480
501
|
*
|
|
481
502
|
* @example
|
|
482
503
|
* ```typescript
|
|
@@ -493,11 +514,11 @@ declare function useOnQuery<D = unknown, R = unknown>(host: ReactiveElement, { t
|
|
|
493
514
|
/**
|
|
494
515
|
* Interface for the IoC context value.
|
|
495
516
|
*
|
|
496
|
-
* @group
|
|
517
|
+
* @group Context
|
|
497
518
|
*/
|
|
498
519
|
interface IocContext {
|
|
499
520
|
/**
|
|
500
|
-
* The
|
|
521
|
+
* The IoC container instance.
|
|
501
522
|
*/
|
|
502
523
|
readonly container: Container;
|
|
503
524
|
/**
|
|
@@ -510,18 +531,18 @@ interface IocContext {
|
|
|
510
531
|
readonly nextRevision: () => number;
|
|
511
532
|
}
|
|
512
533
|
/**
|
|
513
|
-
* Lit context for providing and consuming the IoC container.
|
|
534
|
+
* Lit context object for providing and consuming the IoC container.
|
|
514
535
|
*
|
|
515
|
-
* @group
|
|
536
|
+
* @group Context
|
|
516
537
|
*/
|
|
517
|
-
declare const
|
|
538
|
+
declare const IocContextObject: {
|
|
518
539
|
__context__: IocContext;
|
|
519
540
|
};
|
|
520
541
|
|
|
521
542
|
/**
|
|
522
|
-
*
|
|
543
|
+
* Represents options for the {@link IocProviderController}.
|
|
523
544
|
*
|
|
524
|
-
* @group
|
|
545
|
+
* @group Provision
|
|
525
546
|
*/
|
|
526
547
|
interface IocProviderControllerOptions {
|
|
527
548
|
/**
|
|
@@ -536,13 +557,16 @@ interface IocProviderControllerOptions {
|
|
|
536
557
|
/**
|
|
537
558
|
* Controller that provides an IoC container context to the host element and its children.
|
|
538
559
|
*
|
|
560
|
+
* @remarks
|
|
539
561
|
* It manages the lifecycle of the container and handles revision updates to notify consumers.
|
|
562
|
+
* The container is created (or used from options) when the controller is instantiated.
|
|
563
|
+
* Seed data is applied when the host connects.
|
|
540
564
|
*
|
|
541
|
-
* @group
|
|
565
|
+
* @group Provision
|
|
542
566
|
*/
|
|
543
567
|
declare class IocProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
|
|
544
568
|
private readonly host;
|
|
545
|
-
protected readonly provider: ContextProvider<typeof
|
|
569
|
+
protected readonly provider: ContextProvider<typeof IocContextObject>;
|
|
546
570
|
protected readonly seed?: AnyObject;
|
|
547
571
|
protected revision: number;
|
|
548
572
|
/**
|
|
@@ -550,14 +574,14 @@ declare class IocProviderController<E extends ReactiveControllerHost & HTMLEleme
|
|
|
550
574
|
*/
|
|
551
575
|
container: Container;
|
|
552
576
|
/**
|
|
553
|
-
* @returns
|
|
577
|
+
* @returns Current {@link IocContext} value served to child consumers.
|
|
554
578
|
*/
|
|
555
579
|
get value(): IocContext;
|
|
556
580
|
/**
|
|
557
|
-
* @param host -
|
|
558
|
-
* @param options -
|
|
559
|
-
* @param options.container -
|
|
560
|
-
* @param options.seed -
|
|
581
|
+
* @param host - The host element.
|
|
582
|
+
* @param options - Provisioning options.
|
|
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.
|
|
561
585
|
*/
|
|
562
586
|
constructor(host: E, { container, seed }?: IocProviderControllerOptions);
|
|
563
587
|
hostConnected(): void;
|
|
@@ -566,28 +590,34 @@ declare class IocProviderController<E extends ReactiveControllerHost & HTMLEleme
|
|
|
566
590
|
}
|
|
567
591
|
|
|
568
592
|
/**
|
|
569
|
-
*
|
|
593
|
+
* Represents interface for the {@link iocProvide} decorator.
|
|
594
|
+
*
|
|
595
|
+
* @remarks
|
|
596
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
570
597
|
*
|
|
571
|
-
* @group
|
|
598
|
+
* @group Provision
|
|
572
599
|
*/
|
|
573
600
|
interface IocProviderDecorator<E extends ReactiveElement = ReactiveElement> {
|
|
574
601
|
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends IocProviderController<E>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
|
|
575
602
|
<K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, IocProviderController<E>>;
|
|
576
603
|
}
|
|
577
604
|
/**
|
|
578
|
-
* Decorator
|
|
605
|
+
* Decorator that provides an IoC container to child components.
|
|
579
606
|
*
|
|
580
|
-
* @
|
|
607
|
+
* @remarks
|
|
608
|
+
* The container is provided via Lit context. It is created (or used from options) when the host connects.
|
|
581
609
|
*
|
|
582
|
-
* @
|
|
583
|
-
*
|
|
584
|
-
* @param options
|
|
585
|
-
* @
|
|
610
|
+
* @group Provision
|
|
611
|
+
*
|
|
612
|
+
* @param options - Provisioning options.
|
|
613
|
+
* @param options.container - Optional existing container to use, if not provided, a new one will be created.
|
|
614
|
+
* @param options.seed - Optional seed data to apply to the container.
|
|
615
|
+
* @returns An instance of {@link IocProviderDecorator}.
|
|
586
616
|
*
|
|
587
617
|
* @example
|
|
588
618
|
* ```typescript
|
|
589
619
|
* class MyRootElement extends LitElement {
|
|
590
|
-
* @iocProvide({ seed: { someData:
|
|
620
|
+
* @iocProvide({ seed: { someData: "value" } })
|
|
591
621
|
* private ioc!: IocProviderController;
|
|
592
622
|
* }
|
|
593
623
|
* ```
|
|
@@ -595,14 +625,18 @@ interface IocProviderDecorator<E extends ReactiveElement = ReactiveElement> {
|
|
|
595
625
|
declare function iocProvide<E extends ReactiveElement>({ container, seed, }?: IocProviderControllerOptions): IocProviderDecorator<E>;
|
|
596
626
|
|
|
597
627
|
/**
|
|
628
|
+
* Represents a function that returns a value of type `T`.
|
|
629
|
+
*
|
|
598
630
|
* @group general-types
|
|
631
|
+
*
|
|
632
|
+
* @template T - The return type of the function.
|
|
599
633
|
*/
|
|
600
634
|
type Callable<T> = () => T;
|
|
601
635
|
|
|
602
636
|
/**
|
|
603
|
-
*
|
|
637
|
+
* Represents options for the {@link InjectablesProviderController}.
|
|
604
638
|
*
|
|
605
|
-
* @group
|
|
639
|
+
* @group Provision
|
|
606
640
|
*/
|
|
607
641
|
interface InjectablesProviderControllerOptions {
|
|
608
642
|
/**
|
|
@@ -626,14 +660,14 @@ interface InjectablesProviderControllerOptions {
|
|
|
626
660
|
seeds?: SeedEntries;
|
|
627
661
|
}
|
|
628
662
|
/**
|
|
629
|
-
* Controller that binds
|
|
630
|
-
* and unbinds them when the host disconnects.
|
|
663
|
+
* Controller that binds injectables to an IoC container for the host element's lifetime.
|
|
631
664
|
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
665
|
+
* @remarks
|
|
666
|
+
* Entries are bound when the host connects and unbound when it disconnects.
|
|
667
|
+
* If no `into` context is provided, it uses the nearest {@link IocProviderController}.
|
|
668
|
+
* Seeds are applied before entries are bound.
|
|
635
669
|
*
|
|
636
|
-
* @group
|
|
670
|
+
* @group Provision
|
|
637
671
|
*
|
|
638
672
|
* @example
|
|
639
673
|
* ```typescript
|
|
@@ -648,7 +682,7 @@ interface InjectablesProviderControllerOptions {
|
|
|
648
682
|
*/
|
|
649
683
|
declare class InjectablesProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
|
|
650
684
|
private readonly host;
|
|
651
|
-
protected readonly consumer?: ContextConsumer<typeof
|
|
685
|
+
protected readonly consumer?: ContextConsumer<typeof IocContextObject, E>;
|
|
652
686
|
private readonly entries;
|
|
653
687
|
private readonly activate;
|
|
654
688
|
private readonly seeds;
|
|
@@ -658,12 +692,12 @@ declare class InjectablesProviderController<E extends ReactiveControllerHost & H
|
|
|
658
692
|
*/
|
|
659
693
|
private boundContext;
|
|
660
694
|
/**
|
|
661
|
-
* @param host -
|
|
662
|
-
* @param options -
|
|
663
|
-
* @param options.entries -
|
|
664
|
-
* @param options.into -
|
|
665
|
-
* @param options.activate -
|
|
666
|
-
* @param options.seeds -
|
|
695
|
+
* @param host - The host element.
|
|
696
|
+
* @param options - Provisioning options.
|
|
697
|
+
* @param options.entries - List of service entries to bind to the container.
|
|
698
|
+
* @param options.into - Target IoC context; if omitted, uses the nearest provider context.
|
|
699
|
+
* @param options.activate - List of service identifiers to activate immediately after binding.
|
|
700
|
+
* @param options.seeds - Seed data applied before binding.
|
|
667
701
|
*/
|
|
668
702
|
constructor(host: E, options: InjectablesProviderControllerOptions);
|
|
669
703
|
hostConnected(): void;
|
|
@@ -673,11 +707,12 @@ declare class InjectablesProviderController<E extends ReactiveControllerHost & H
|
|
|
673
707
|
}
|
|
674
708
|
|
|
675
709
|
/**
|
|
676
|
-
*
|
|
710
|
+
* Represents type for the {@link injectablesProvide} decorator.
|
|
677
711
|
*
|
|
678
|
-
*
|
|
712
|
+
* @remarks
|
|
713
|
+
* Supports both TC39 and legacy experimental decorators.
|
|
679
714
|
*
|
|
680
|
-
* @group
|
|
715
|
+
* @group Provision
|
|
681
716
|
*/
|
|
682
717
|
interface InjectablesProviderDecorator<T extends ReactiveElement = ReactiveElement> {
|
|
683
718
|
<C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends InjectablesProviderController<T>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
|
|
@@ -686,38 +721,32 @@ interface InjectablesProviderDecorator<T extends ReactiveElement = ReactiveEleme
|
|
|
686
721
|
/**
|
|
687
722
|
* Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
|
|
688
723
|
*
|
|
724
|
+
* @remarks
|
|
689
725
|
* Entries are bound when the host connects and unbound when it disconnects.
|
|
690
|
-
* The decorated accessor or property holds the resulting {@link InjectablesProviderController} instance.
|
|
691
726
|
*
|
|
692
|
-
* @group
|
|
727
|
+
* @group Provision
|
|
693
728
|
*
|
|
694
|
-
* @param options -
|
|
695
|
-
* @returns
|
|
729
|
+
* @param options - Provisioning options.
|
|
730
|
+
* @returns An instance of {@link InjectablesProviderDecorator}.
|
|
696
731
|
*
|
|
697
732
|
* @example
|
|
698
733
|
* ```typescript
|
|
699
734
|
* class MyComponent extends LitElement {
|
|
700
735
|
* @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
|
|
701
|
-
* public
|
|
736
|
+
* public controller!: InjectablesProviderController<MyComponent>;
|
|
702
737
|
* }
|
|
703
738
|
* ```
|
|
704
739
|
*/
|
|
705
740
|
declare function injectablesProvide<E extends ReactiveElement = ReactiveElement>(options: InjectablesProviderControllerOptions): InjectablesProviderDecorator<E>;
|
|
706
741
|
|
|
707
742
|
/**
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
* Entries are bound when the host connects and unbound when it disconnects.
|
|
743
|
+
* Hook that binds injectables to the nearest IoC container for the host element's lifetime.
|
|
711
744
|
*
|
|
712
|
-
* @group
|
|
745
|
+
* @group Provision
|
|
713
746
|
*
|
|
714
|
-
* @param host -
|
|
715
|
-
* @param options -
|
|
716
|
-
* @
|
|
717
|
-
* @param options.into - target IoC context; if omitted, uses the nearest provider context
|
|
718
|
-
* @param options.activate - list of service identifiers to activate immediately after binding
|
|
719
|
-
* @param options.seeds - seed data applied before binding
|
|
720
|
-
* @returns the controller instance
|
|
747
|
+
* @param host - The host element.
|
|
748
|
+
* @param options - Provisioning options.
|
|
749
|
+
* @returns An instance of {@link InjectablesProviderController}.
|
|
721
750
|
*
|
|
722
751
|
* @example
|
|
723
752
|
* ```typescript
|
|
@@ -732,9 +761,9 @@ declare function injectablesProvide<E extends ReactiveElement = ReactiveElement>
|
|
|
732
761
|
declare function useInjectablesProvider<E extends ReactiveControllerHost & HTMLElement>(host: E, options: InjectablesProviderControllerOptions): InjectablesProviderController<E>;
|
|
733
762
|
|
|
734
763
|
/**
|
|
735
|
-
*
|
|
764
|
+
* Represents options for the {@link useIocProvision} hook.
|
|
736
765
|
*
|
|
737
|
-
* @group
|
|
766
|
+
* @group Provision
|
|
738
767
|
*/
|
|
739
768
|
interface UseIocProvisionOptions {
|
|
740
769
|
/**
|
|
@@ -747,24 +776,22 @@ interface UseIocProvisionOptions {
|
|
|
747
776
|
seed?: AnyObject;
|
|
748
777
|
}
|
|
749
778
|
/**
|
|
750
|
-
* Hook
|
|
779
|
+
* Hook that provides an IoC container to the host element and its children.
|
|
751
780
|
*
|
|
752
|
-
* @group
|
|
781
|
+
* @group Provision
|
|
753
782
|
*
|
|
754
|
-
* @param host -
|
|
755
|
-
* @param options -
|
|
756
|
-
* @
|
|
757
|
-
* @param options.seed - optional seed data to apply to the container
|
|
758
|
-
* @returns ioc provision controller instance
|
|
783
|
+
* @param host - The host element.
|
|
784
|
+
* @param options - Provisioning options.
|
|
785
|
+
* @returns An instance of {@link IocProviderController}.
|
|
759
786
|
*
|
|
760
787
|
* @example
|
|
761
788
|
* ```typescript
|
|
762
789
|
* class MyRootElement extends LitElement {
|
|
763
|
-
* private ioc = useIocProvision(this, { seed: { initialData:
|
|
790
|
+
* private ioc = useIocProvision(this, { seed: { initialData: "..." } });
|
|
764
791
|
* }
|
|
765
792
|
* ```
|
|
766
793
|
*/
|
|
767
794
|
declare function useIocProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, options?: UseIocProvisionOptions): IocProviderController<E>;
|
|
768
795
|
|
|
769
|
-
export {
|
|
770
|
-
export type { InjectablesProviderControllerOptions, InjectablesProviderDecorator, InjectionDecorator, InjectionOptions, IocProviderControllerOptions, IocProviderDecorator, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, UseInjectionOptions, UseInjectionValue, UseIocProvisionOptions, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions };
|
|
796
|
+
export { InjectablesProviderController, IocContextObject, IocProviderController, OnCommandController, OnEventController, OnQueryController, injectablesProvide, injection, iocProvide, onCommand, onEvent, onQuery, useInjectablesProvider, useInjection, useIocProvision, useOnCommand, useOnEvents, useOnQuery };
|
|
797
|
+
export type { InjectablesProviderControllerOptions, InjectablesProviderDecorator, InjectionDecorator, InjectionOptions, IocContext, IocProviderControllerOptions, IocProviderDecorator, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, UseInjectionOptions, UseInjectionValue, UseIocProvisionOptions, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions };
|