@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/cjs/development/index.js
CHANGED
|
@@ -5,25 +5,25 @@ var core = require('@wirestate/core');
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Unique symbol used as a key for the IoC context.
|
|
9
9
|
*
|
|
10
|
-
* @group
|
|
10
|
+
* @group Context
|
|
11
11
|
*/
|
|
12
|
-
var
|
|
12
|
+
var CONTAINER_KEY = Symbol("ContainerContext");
|
|
13
13
|
/**
|
|
14
|
-
* Lit context for providing and consuming the
|
|
14
|
+
* Lit context object for providing and consuming the container.
|
|
15
15
|
*
|
|
16
|
-
* @group
|
|
16
|
+
* @group Context
|
|
17
17
|
*/
|
|
18
|
-
var ContainerContext = context.createContext(
|
|
18
|
+
var ContainerContext = context.createContext(CONTAINER_KEY);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Decorator to inject a service from the IoC container into a Lit element property.
|
|
22
22
|
*
|
|
23
|
-
* @group
|
|
23
|
+
* @group Consumption
|
|
24
24
|
*
|
|
25
|
-
* @param optionsOrInjectionId -
|
|
26
|
-
* @returns
|
|
25
|
+
* @param optionsOrInjectionId - Injection options or service identifier.
|
|
26
|
+
* @returns An instance of {@link InjectionDecorator}.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
@@ -62,8 +62,8 @@ function injection(optionsOrInjectionId) {
|
|
|
62
62
|
var _this = this;
|
|
63
63
|
new context.ContextConsumer(this, {
|
|
64
64
|
context: ContainerContext,
|
|
65
|
-
callback: function (
|
|
66
|
-
protoOrTarget.set.call(_this,
|
|
65
|
+
callback: function (container) {
|
|
66
|
+
protoOrTarget.set.call(_this, container.get(injectionId));
|
|
67
67
|
},
|
|
68
68
|
subscribe: !once
|
|
69
69
|
});
|
|
@@ -73,8 +73,8 @@ function injection(optionsOrInjectionId) {
|
|
|
73
73
|
protoOrTarget.constructor.addInitializer(function (element) {
|
|
74
74
|
new context.ContextConsumer(element, {
|
|
75
75
|
context: ContainerContext,
|
|
76
|
-
callback: function (
|
|
77
|
-
element[nameOrContext] =
|
|
76
|
+
callback: function (container) {
|
|
77
|
+
element[nameOrContext] = container.get(injectionId);
|
|
78
78
|
},
|
|
79
79
|
subscribe: !once
|
|
80
80
|
});
|
|
@@ -84,13 +84,48 @@ function injection(optionsOrInjectionId) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* Hook (
|
|
87
|
+
* Hook (consumer) to access the active container from the nearest parent context.
|
|
88
88
|
*
|
|
89
|
-
* @
|
|
89
|
+
* @remarks
|
|
90
|
+
* The returned value updates when the nearest provided container changes.
|
|
90
91
|
*
|
|
91
|
-
* @
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
92
|
+
* @group Consumption
|
|
93
|
+
*
|
|
94
|
+
* @param host - The host element.
|
|
95
|
+
* @returns An instance of {@link UseContainerValue}.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* class MyElement extends LitElement {
|
|
100
|
+
* private container: UseContainerValue = useContainer(this);
|
|
101
|
+
*
|
|
102
|
+
* public render() {
|
|
103
|
+
* return html`<div>${this.container.value.isBound(MyService)}</div>`;
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function useContainer(host) {
|
|
109
|
+
var current = {
|
|
110
|
+
value: null
|
|
111
|
+
};
|
|
112
|
+
new context.ContextConsumer(host, {
|
|
113
|
+
context: ContainerContext,
|
|
114
|
+
callback: function (container) {
|
|
115
|
+
current.value = container;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return current;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Hook (controller) to inject a service from the IoC container.
|
|
123
|
+
*
|
|
124
|
+
* @group Consumption
|
|
125
|
+
*
|
|
126
|
+
* @param host - The host element.
|
|
127
|
+
* @param optionsOrInjectionId - Injection options or service identifier.
|
|
128
|
+
* @returns An instance of {@link UseInjectionValue}.
|
|
94
129
|
*
|
|
95
130
|
* @example
|
|
96
131
|
* ```typescript
|
|
@@ -128,25 +163,64 @@ function useInjection(host, optionsOrInjectionId) {
|
|
|
128
163
|
new context.ContextConsumer(host, {
|
|
129
164
|
context: ContainerContext,
|
|
130
165
|
subscribe: !once,
|
|
131
|
-
callback: function (
|
|
132
|
-
current.value =
|
|
166
|
+
callback: function (container) {
|
|
167
|
+
current.value = container.get(injectionId);
|
|
133
168
|
}
|
|
134
169
|
});
|
|
135
170
|
return current;
|
|
136
171
|
}
|
|
137
172
|
|
|
138
173
|
/**
|
|
139
|
-
*
|
|
174
|
+
* Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
|
|
175
|
+
*
|
|
176
|
+
* @remarks
|
|
177
|
+
* The returned value updates when the nearest provided container changes.
|
|
140
178
|
*
|
|
179
|
+
* @group Consumption
|
|
180
|
+
*
|
|
181
|
+
* @param host - The host element.
|
|
182
|
+
* @returns An instance of {@link UseScopeValue}.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* class MyElement extends LitElement {
|
|
187
|
+
* private scope: UseScopeValue = useScope(this);
|
|
188
|
+
*
|
|
189
|
+
* public connectedCallback(): void {
|
|
190
|
+
* super.connectedCallback();
|
|
191
|
+
* this.scope.value.emitEvent("UI_READY");
|
|
192
|
+
* }
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
function useScope(host) {
|
|
197
|
+
var current = {
|
|
198
|
+
value: undefined,
|
|
199
|
+
injectionId: core.WireScope
|
|
200
|
+
};
|
|
201
|
+
new context.ContextConsumer(host, {
|
|
202
|
+
context: ContainerContext,
|
|
203
|
+
subscribe: true,
|
|
204
|
+
callback: function (container) {
|
|
205
|
+
current.value = container.get(core.WireScope);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return current;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Controller that registers a command handler for the host element's lifetime.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
141
215
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
142
|
-
*
|
|
216
|
+
* It automatically re-registers if the IoC container is updated.
|
|
143
217
|
*
|
|
144
|
-
* @group
|
|
218
|
+
* @group Commands
|
|
145
219
|
*/
|
|
146
220
|
var OnCommandController = /** @class */function () {
|
|
147
221
|
/**
|
|
148
222
|
* @param host - The host element.
|
|
149
|
-
* @param type -
|
|
223
|
+
* @param type - Unique identifier of the command to handle.
|
|
150
224
|
* @param handler - The command handler function.
|
|
151
225
|
*/
|
|
152
226
|
function OnCommandController(host, type, handler) {
|
|
@@ -159,8 +233,8 @@ var OnCommandController = /** @class */function () {
|
|
|
159
233
|
new context.ContextConsumer(host, {
|
|
160
234
|
context: ContainerContext,
|
|
161
235
|
subscribe: true,
|
|
162
|
-
callback: function (
|
|
163
|
-
_this.bus =
|
|
236
|
+
callback: function (container) {
|
|
237
|
+
_this.bus = container.get(core.CommandBus);
|
|
164
238
|
if (host.isConnected) {
|
|
165
239
|
_this.reregister();
|
|
166
240
|
}
|
|
@@ -188,20 +262,21 @@ var OnCommandController = /** @class */function () {
|
|
|
188
262
|
}();
|
|
189
263
|
|
|
190
264
|
/**
|
|
191
|
-
* Decorator
|
|
265
|
+
* Decorator for Lit element methods that handle a specific command.
|
|
192
266
|
*
|
|
193
|
-
*
|
|
267
|
+
* @remarks
|
|
268
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
194
269
|
*
|
|
195
|
-
* @group
|
|
270
|
+
* @group Commands
|
|
196
271
|
*
|
|
197
|
-
* @param type - the command
|
|
198
|
-
* @returns
|
|
272
|
+
* @param type - Unique identifier of the command to handle.
|
|
273
|
+
* @returns A method decorator function.
|
|
199
274
|
*
|
|
200
275
|
* @example
|
|
201
276
|
* ```typescript
|
|
202
277
|
* class MyElement extends LitElement {
|
|
203
278
|
* @onCommand("SAVE")
|
|
204
|
-
* private
|
|
279
|
+
* private onSave(data: SomeData): void {
|
|
205
280
|
* // handle command
|
|
206
281
|
* }
|
|
207
282
|
* }
|
|
@@ -229,15 +304,15 @@ function onCommand(type) {
|
|
|
229
304
|
}
|
|
230
305
|
|
|
231
306
|
/**
|
|
232
|
-
*
|
|
307
|
+
* Hook that registers a command handler for the host element's lifetime.
|
|
233
308
|
*
|
|
234
|
-
* @group
|
|
309
|
+
* @group Commands
|
|
235
310
|
*
|
|
236
|
-
* @param host -
|
|
237
|
-
* @param options -
|
|
238
|
-
* @param options.type -
|
|
239
|
-
* @param options.handler -
|
|
240
|
-
* @returns
|
|
311
|
+
* @param host - The host element.
|
|
312
|
+
* @param options - Command handling options.
|
|
313
|
+
* @param options.type - The command type to listen for.
|
|
314
|
+
* @param options.handler - The command handler function.
|
|
315
|
+
* @returns The command controller instance.
|
|
241
316
|
*
|
|
242
317
|
* @example
|
|
243
318
|
* ```typescript
|
|
@@ -256,17 +331,19 @@ function useOnCommand(host, _a) {
|
|
|
256
331
|
}
|
|
257
332
|
|
|
258
333
|
/**
|
|
259
|
-
* Controller that subscribes to events
|
|
334
|
+
* Controller that subscribes to events for the host element's lifetime.
|
|
260
335
|
*
|
|
261
|
-
*
|
|
336
|
+
* @remarks
|
|
337
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
338
|
+
* It automatically re-subscribes if the IoC container is updated.
|
|
262
339
|
*
|
|
263
|
-
* @group
|
|
340
|
+
* @group Events
|
|
264
341
|
*/
|
|
265
342
|
var OnEventController = /** @class */function () {
|
|
266
343
|
/**
|
|
267
|
-
* @param host -
|
|
268
|
-
* @param types -
|
|
269
|
-
* @param handler -
|
|
344
|
+
* @param host - The host element.
|
|
345
|
+
* @param types - Event types to listen for. If null, all events will be handled.
|
|
346
|
+
* @param handler - The event handler function.
|
|
270
347
|
*/
|
|
271
348
|
function OnEventController(host, types, handler) {
|
|
272
349
|
var _this = this;
|
|
@@ -278,8 +355,8 @@ var OnEventController = /** @class */function () {
|
|
|
278
355
|
new context.ContextConsumer(host, {
|
|
279
356
|
context: ContainerContext,
|
|
280
357
|
subscribe: true,
|
|
281
|
-
callback: function (
|
|
282
|
-
_this.bus =
|
|
358
|
+
callback: function (container) {
|
|
359
|
+
_this.bus = container.get(core.EventBus);
|
|
283
360
|
if (host.isConnected) {
|
|
284
361
|
_this.resubscribe();
|
|
285
362
|
}
|
|
@@ -316,19 +393,22 @@ var OnEventController = /** @class */function () {
|
|
|
316
393
|
}();
|
|
317
394
|
|
|
318
395
|
/**
|
|
319
|
-
* Decorator
|
|
396
|
+
* Decorator for Lit element methods that handle events from the event bus.
|
|
320
397
|
*
|
|
321
|
-
* @
|
|
398
|
+
* @remarks
|
|
399
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
400
|
+
*
|
|
401
|
+
* @group Events
|
|
322
402
|
*
|
|
323
403
|
* @param types - Event types to listen for. If omitted, all events will be handled.
|
|
324
|
-
* @returns
|
|
404
|
+
* @returns A method decorator function.
|
|
325
405
|
*
|
|
326
406
|
* @example
|
|
327
407
|
* ```typescript
|
|
328
408
|
* class MyElement extends LitElement {
|
|
329
409
|
* @onEvent()
|
|
330
410
|
* private onMyEvent(event: Event) {
|
|
331
|
-
* console.log(
|
|
411
|
+
* console.log("Event received:", event);
|
|
332
412
|
* }
|
|
333
413
|
* }
|
|
334
414
|
* ```
|
|
@@ -336,9 +416,9 @@ var OnEventController = /** @class */function () {
|
|
|
336
416
|
* @example
|
|
337
417
|
* ```typescript
|
|
338
418
|
* class MyElement extends LitElement {
|
|
339
|
-
* @onEvent(
|
|
419
|
+
* @onEvent("MY_EVENT_TYPE")
|
|
340
420
|
* private onMyEvent(event: MyEvent) {
|
|
341
|
-
* console.log(
|
|
421
|
+
* console.log("Event received:", event);
|
|
342
422
|
* }
|
|
343
423
|
* }
|
|
344
424
|
* ```
|
|
@@ -346,9 +426,9 @@ var OnEventController = /** @class */function () {
|
|
|
346
426
|
* @example
|
|
347
427
|
* ```typescript
|
|
348
428
|
* class MyElement extends LitElement {
|
|
349
|
-
* @onEvent([
|
|
429
|
+
* @onEvent(["MY_EVENT_TYPE_1", "MY_EVENT_TYPE_2"])
|
|
350
430
|
* private onMyEvent(event: Event) {
|
|
351
|
-
* console.log(
|
|
431
|
+
* console.log("Event received:", event);
|
|
352
432
|
* }
|
|
353
433
|
* }
|
|
354
434
|
* ```
|
|
@@ -376,15 +456,15 @@ function onEvent(types) {
|
|
|
376
456
|
}
|
|
377
457
|
|
|
378
458
|
/**
|
|
379
|
-
* Hook
|
|
459
|
+
* Hook that subscribes to events for the host element's lifetime.
|
|
380
460
|
*
|
|
381
|
-
* @group
|
|
461
|
+
* @group Events
|
|
382
462
|
*
|
|
383
|
-
* @param host -
|
|
384
|
-
* @param options -
|
|
385
|
-
* @param options.handler -
|
|
386
|
-
* @param options.types -
|
|
387
|
-
* @returns
|
|
463
|
+
* @param host - The host element.
|
|
464
|
+
* @param options - Event handling options.
|
|
465
|
+
* @param options.handler - Event handler function.
|
|
466
|
+
* @param options.types - Event types to listen for, if null or undefined, all events will be handled.
|
|
467
|
+
* @returns An instance of {@link OnEventController}.
|
|
388
468
|
*
|
|
389
469
|
* @example
|
|
390
470
|
* ```typescript
|
|
@@ -399,7 +479,7 @@ function onEvent(types) {
|
|
|
399
479
|
* ```typescript
|
|
400
480
|
* class MyElement extends LitElement {
|
|
401
481
|
* private eventHandler = useOnEvents(this, {
|
|
402
|
-
* types: [
|
|
482
|
+
* types: ["MY_EVENT"],
|
|
403
483
|
* handler: (event) => console.log(event),
|
|
404
484
|
* });
|
|
405
485
|
* }
|
|
@@ -415,16 +495,17 @@ function useOnEvents(host, _a) {
|
|
|
415
495
|
/**
|
|
416
496
|
* Reactive controller that registers a query handler on the {@link QueryBus} for the host element's lifetime.
|
|
417
497
|
*
|
|
498
|
+
* @remarks
|
|
418
499
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
419
|
-
*
|
|
500
|
+
* It automatically re-registers if the IoC container is updated.
|
|
420
501
|
*
|
|
421
|
-
* @group
|
|
502
|
+
* @group Queries
|
|
422
503
|
*/
|
|
423
504
|
var OnQueryController = /** @class */function () {
|
|
424
505
|
/**
|
|
425
|
-
* @param host -
|
|
426
|
-
* @param type - the query
|
|
427
|
-
* @param handler -
|
|
506
|
+
* @param host - The host element.
|
|
507
|
+
* @param type - Unique identifier of the query to handle.
|
|
508
|
+
* @param handler - The query handler function.
|
|
428
509
|
*/
|
|
429
510
|
function OnQueryController(host, type, handler) {
|
|
430
511
|
var _this = this;
|
|
@@ -436,8 +517,8 @@ var OnQueryController = /** @class */function () {
|
|
|
436
517
|
new context.ContextConsumer(host, {
|
|
437
518
|
context: ContainerContext,
|
|
438
519
|
subscribe: true,
|
|
439
|
-
callback: function (
|
|
440
|
-
_this.bus =
|
|
520
|
+
callback: function (container) {
|
|
521
|
+
_this.bus = container.get(core.QueryBus);
|
|
441
522
|
if (host.isConnected) {
|
|
442
523
|
_this.reregister();
|
|
443
524
|
}
|
|
@@ -465,20 +546,21 @@ var OnQueryController = /** @class */function () {
|
|
|
465
546
|
}();
|
|
466
547
|
|
|
467
548
|
/**
|
|
468
|
-
* Decorator
|
|
549
|
+
* Decorator for Lit element methods that handle a specific query.
|
|
469
550
|
*
|
|
470
|
-
*
|
|
551
|
+
* @remarks
|
|
552
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
471
553
|
*
|
|
472
|
-
* @group
|
|
554
|
+
* @group Queries
|
|
473
555
|
*
|
|
474
|
-
* @param type - the query
|
|
475
|
-
* @returns
|
|
556
|
+
* @param type - Unique identifier of the query to handle.
|
|
557
|
+
* @returns A method decorator function.
|
|
476
558
|
*
|
|
477
559
|
* @example
|
|
478
560
|
* ```typescript
|
|
479
561
|
* class MyElement extends LitElement {
|
|
480
562
|
* @onQuery("GET_USER_NAME")
|
|
481
|
-
*
|
|
563
|
+
* private onGetUserName(data: QueryData) {
|
|
482
564
|
* return "Alice";
|
|
483
565
|
* }
|
|
484
566
|
* }
|
|
@@ -506,15 +588,15 @@ function onQuery(type) {
|
|
|
506
588
|
}
|
|
507
589
|
|
|
508
590
|
/**
|
|
509
|
-
*
|
|
591
|
+
* Hook that registers a query handler for the host element's lifetime.
|
|
510
592
|
*
|
|
511
|
-
* @group
|
|
593
|
+
* @group Queries
|
|
512
594
|
*
|
|
513
|
-
* @param host -
|
|
514
|
-
* @param options -
|
|
515
|
-
* @param options.type -
|
|
516
|
-
* @param options.handler -
|
|
517
|
-
* @returns
|
|
595
|
+
* @param host - The host element.
|
|
596
|
+
* @param options - Query handling options.
|
|
597
|
+
* @param options.type - The query type to handle.
|
|
598
|
+
* @param options.handler - The query handler function.
|
|
599
|
+
* @returns An instance of {@link OnQueryController}.
|
|
518
600
|
*
|
|
519
601
|
* @example
|
|
520
602
|
* ```typescript
|
|
@@ -532,110 +614,211 @@ function useOnQuery(host, _a) {
|
|
|
532
614
|
return new OnQueryController(host, type, handler);
|
|
533
615
|
}
|
|
534
616
|
|
|
617
|
+
var ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
618
|
+
|
|
535
619
|
/**
|
|
536
|
-
*
|
|
620
|
+
* Provider that exposes an IoC container context to the host element and its children.
|
|
621
|
+
*
|
|
622
|
+
* @remarks
|
|
623
|
+
* The provider supports two modes:
|
|
537
624
|
*
|
|
538
|
-
*
|
|
625
|
+
* - External mode: `container` is an existing {@link Container}. The
|
|
626
|
+
* provider passes it through context and does not alter its lifecycle.
|
|
627
|
+
* - Managed mode: `options` is {@link CreateContainerOptions}. The provider
|
|
628
|
+
* creates a container during construction without eager activation,
|
|
629
|
+
* activates configured entries when the host connects, disposes the
|
|
630
|
+
* container when the host disconnects, and recreates it on reconnect.
|
|
539
631
|
*
|
|
540
|
-
* @group
|
|
632
|
+
* @group Provision
|
|
541
633
|
*/
|
|
542
|
-
var
|
|
634
|
+
var ContainerProvider = /** @class */function (_super) {
|
|
635
|
+
tslib.__extends(ContainerProvider, _super);
|
|
543
636
|
/**
|
|
544
|
-
* @param host -
|
|
545
|
-
* @param options -
|
|
546
|
-
* @param options.container -
|
|
547
|
-
* @param options.
|
|
637
|
+
* @param host - The host element.
|
|
638
|
+
* @param options - Provisioning options.
|
|
639
|
+
* @param options.container - External container instance to provide.
|
|
640
|
+
* @param options.options - Managed container creation options.
|
|
548
641
|
*/
|
|
549
|
-
function
|
|
550
|
-
var _b = _a === void 0 ? {} : _a,
|
|
551
|
-
container = _b.container,
|
|
552
|
-
seed = _b.seed;
|
|
642
|
+
function ContainerProvider(host, options) {
|
|
553
643
|
var _this = this;
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
644
|
+
if (!options.container && !options.options) {
|
|
645
|
+
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
|
|
646
|
+
} else if (options.container && options.options) {
|
|
647
|
+
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
|
|
648
|
+
}
|
|
649
|
+
_this = _super.call(this, host, {
|
|
560
650
|
context: ContainerContext,
|
|
561
|
-
initialValue: {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
651
|
+
initialValue: options.container ? options.container : core.createContainer(tslib.__assign(tslib.__assign({}, options.options), {
|
|
652
|
+
activate: []
|
|
653
|
+
}))
|
|
654
|
+
}) || this;
|
|
655
|
+
_this.destroyed = false;
|
|
656
|
+
_this.options = options.options;
|
|
657
|
+
return _this;
|
|
658
|
+
}
|
|
659
|
+
ContainerProvider.prototype.hostConnected = function () {
|
|
660
|
+
var _a;
|
|
661
|
+
if (this.options) {
|
|
662
|
+
if (this.destroyed) {
|
|
663
|
+
this.value = core.createContainer(this.options);
|
|
664
|
+
this.destroyed = false;
|
|
665
|
+
} else {
|
|
666
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.activate) {
|
|
667
|
+
for (var _i = 0, _b = this.options.activate; _i < _b.length; _i++) {
|
|
668
|
+
var entry = _b[_i];
|
|
669
|
+
this.value.get(entry);
|
|
670
|
+
}
|
|
566
671
|
}
|
|
567
672
|
}
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
Object.defineProperty(IocProviderController.prototype, "value", {
|
|
571
|
-
/**
|
|
572
|
-
* @returns current {@link IocContext} value served to child consumers
|
|
573
|
-
*/
|
|
574
|
-
get: function () {
|
|
575
|
-
return this.provider.value;
|
|
576
|
-
},
|
|
577
|
-
enumerable: false,
|
|
578
|
-
configurable: true
|
|
579
|
-
});
|
|
580
|
-
IocProviderController.prototype.hostConnected = function () {
|
|
581
|
-
if (this.seed) {
|
|
582
|
-
core.applySharedSeed(this.container, this.seed);
|
|
583
673
|
}
|
|
674
|
+
_super.prototype.hostConnected.call(this);
|
|
584
675
|
};
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
676
|
+
ContainerProvider.prototype.hostDisconnected = function () {
|
|
677
|
+
if (this.options) {
|
|
678
|
+
this.value.unbindAll();
|
|
679
|
+
this.destroyed = true;
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
return ContainerProvider;
|
|
683
|
+
}(context.ContextProvider);
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Provider that exposes a managed child container for the host element's lifetime.
|
|
687
|
+
*
|
|
688
|
+
* @remarks
|
|
689
|
+
* The provider always owns a child container derived from the nearest parent
|
|
690
|
+
* {@link ContainerContext}. When connected, it creates a child container using
|
|
691
|
+
* the latest parent context, provides it to descendants, destroys it when the
|
|
692
|
+
* host disconnects, and replaces it whenever the parent container changes.
|
|
693
|
+
*
|
|
694
|
+
* @group Provision
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```typescript
|
|
698
|
+
* class MyComponent extends LitElement {
|
|
699
|
+
* private container = new SubContainerProvider(this, {
|
|
700
|
+
* options: {
|
|
701
|
+
* entries: [AuthService, UserService],
|
|
702
|
+
* activate: [AuthService],
|
|
703
|
+
* seeds: [[AuthService, { role: "admin" }]],
|
|
704
|
+
* },
|
|
705
|
+
* });
|
|
706
|
+
* }
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
var SubContainerProvider = /** @class */function (_super) {
|
|
710
|
+
tslib.__extends(SubContainerProvider, _super);
|
|
711
|
+
/**
|
|
712
|
+
* @param host - The host element.
|
|
713
|
+
* @param options - Provisioning options, including child entries, eager activations, and seeds.
|
|
714
|
+
*/
|
|
715
|
+
function SubContainerProvider(host, options) {
|
|
716
|
+
var _this = _super.call(this, host, {
|
|
717
|
+
context: ContainerContext
|
|
718
|
+
}) || this;
|
|
719
|
+
_this.parent = null;
|
|
720
|
+
_this.destroyed = true;
|
|
721
|
+
_this.options = options.options;
|
|
722
|
+
_this.consumer = new context.ContextConsumer(host, {
|
|
723
|
+
context: ContainerContext,
|
|
724
|
+
subscribe: true,
|
|
725
|
+
callback: function (context) {
|
|
726
|
+
var previousParent = _this.parent;
|
|
727
|
+
_this.parent = context;
|
|
728
|
+
if (host.isConnected) {
|
|
729
|
+
if (_this.destroyed || !_this.value || previousParent !== context) {
|
|
730
|
+
_this.destroyContainer();
|
|
731
|
+
_this.createContainer();
|
|
732
|
+
}
|
|
733
|
+
}
|
|
594
734
|
}
|
|
595
735
|
});
|
|
596
|
-
return
|
|
736
|
+
return _this;
|
|
737
|
+
}
|
|
738
|
+
SubContainerProvider.prototype.hostConnected = function () {
|
|
739
|
+
if (this.parent && (this.destroyed || !this.value)) {
|
|
740
|
+
this.destroyContainer();
|
|
741
|
+
this.createContainer();
|
|
742
|
+
}
|
|
743
|
+
_super.prototype.hostConnected.call(this);
|
|
597
744
|
};
|
|
598
|
-
|
|
599
|
-
|
|
745
|
+
SubContainerProvider.prototype.hostDisconnected = function () {
|
|
746
|
+
this.destroyContainer();
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Replaces the currently provided child container with a new one derived
|
|
750
|
+
* from the latest parent context.
|
|
751
|
+
*/
|
|
752
|
+
SubContainerProvider.prototype.createContainer = function () {
|
|
753
|
+
var container = core.createContainer(tslib.__assign(tslib.__assign({}, this.options), {
|
|
754
|
+
parent: this.parent
|
|
755
|
+
}));
|
|
756
|
+
this.destroyed = false;
|
|
757
|
+
this.value = container;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Destroys the currently provided child container.
|
|
761
|
+
*/
|
|
762
|
+
SubContainerProvider.prototype.destroyContainer = function () {
|
|
763
|
+
if (this.value && !this.destroyed) {
|
|
764
|
+
this.value.unbindAll();
|
|
765
|
+
this.destroyed = true;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
return SubContainerProvider;
|
|
769
|
+
}(context.ContextProvider);
|
|
600
770
|
|
|
601
771
|
/**
|
|
602
|
-
* Decorator
|
|
772
|
+
* Decorator that provides an IoC container to child components.
|
|
773
|
+
*
|
|
774
|
+
* @remarks
|
|
775
|
+
* The container is provided via Lit context.
|
|
776
|
+
*
|
|
777
|
+
* - Pass `container` to expose an external container without taking
|
|
778
|
+
* ownership.
|
|
779
|
+
* - Pass `options` to create a managed container during construction,
|
|
780
|
+
* activate configured entries on connect, destroy it on disconnect, and
|
|
781
|
+
* recreate it on reconnect.
|
|
603
782
|
*
|
|
604
|
-
* @group
|
|
783
|
+
* @group Provision
|
|
605
784
|
*
|
|
606
|
-
* @param options -
|
|
607
|
-
* @param options.container -
|
|
608
|
-
* @param options.
|
|
609
|
-
* @returns
|
|
785
|
+
* @param options - Provisioning options.
|
|
786
|
+
* @param options.container - External container instance to provide.
|
|
787
|
+
* @param options.options - Managed container creation options.
|
|
788
|
+
* @returns An instance of {@link ContainerProviderDecorator}.
|
|
610
789
|
*
|
|
611
790
|
* @example
|
|
612
791
|
* ```typescript
|
|
613
792
|
* class MyRootElement extends LitElement {
|
|
614
|
-
* @
|
|
615
|
-
*
|
|
793
|
+
* @containerProvide({
|
|
794
|
+
* options: {
|
|
795
|
+
* seed: { someData: "value" },
|
|
796
|
+
* entries: [LoggerService],
|
|
797
|
+
* },
|
|
798
|
+
* })
|
|
799
|
+
* private containerProvider!: ContainerProvider;
|
|
800
|
+
* }
|
|
801
|
+
* ```
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```typescript
|
|
805
|
+
* class MyRootElement extends LitElement {
|
|
806
|
+
* @containerProvide({ container: container })
|
|
807
|
+
* private containerProvider!: ContainerProvider;
|
|
616
808
|
* }
|
|
617
809
|
* ```
|
|
618
810
|
*/
|
|
619
|
-
function
|
|
620
|
-
var _b = _a === void 0 ? {} : _a,
|
|
621
|
-
container = _b.container,
|
|
622
|
-
seed = _b.seed;
|
|
811
|
+
function containerProvide(options) {
|
|
623
812
|
return function (protoOrTarget, nameOrContext) {
|
|
624
813
|
if (typeof nameOrContext === "object") {
|
|
625
814
|
// Standard decorators:
|
|
626
815
|
nameOrContext.addInitializer(function () {
|
|
627
|
-
protoOrTarget.set.call(this, new
|
|
628
|
-
container: container,
|
|
629
|
-
seed: seed
|
|
630
|
-
}));
|
|
816
|
+
protoOrTarget.set.call(this, new ContainerProvider(this, options));
|
|
631
817
|
});
|
|
632
818
|
} else {
|
|
633
819
|
var controller_1;
|
|
634
820
|
protoOrTarget.constructor.addInitializer(function (element) {
|
|
635
|
-
controller_1 = new
|
|
636
|
-
container: container,
|
|
637
|
-
seed: seed
|
|
638
|
-
});
|
|
821
|
+
controller_1 = new ContainerProvider(element, options);
|
|
639
822
|
});
|
|
640
823
|
return {
|
|
641
824
|
get: function () {
|
|
@@ -649,158 +832,49 @@ function iocProvide(_a) {
|
|
|
649
832
|
};
|
|
650
833
|
}
|
|
651
834
|
|
|
652
|
-
var ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
653
|
-
|
|
654
835
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
836
|
+
* Decorator that provides a managed child container derived from the nearest
|
|
837
|
+
* parent container context.
|
|
657
838
|
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
839
|
+
* @remarks
|
|
840
|
+
* The child container is created from the current parent context when the host
|
|
841
|
+
* connects, destroyed when it disconnects, and recreated when the parent
|
|
842
|
+
* container changes.
|
|
661
843
|
*
|
|
662
|
-
* @group
|
|
844
|
+
* @group Provision
|
|
663
845
|
*
|
|
664
|
-
* @
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
* private services = new InjectablesProviderController(this, {
|
|
668
|
-
* entries: [AuthService, UserService],
|
|
669
|
-
* activate: [AuthService],
|
|
670
|
-
* seeds: [[AuthService, { role: "admin" }]],
|
|
671
|
-
* });
|
|
672
|
-
* }
|
|
673
|
-
* ```
|
|
674
|
-
*/
|
|
675
|
-
var InjectablesProviderController = /** @class */function () {
|
|
676
|
-
/**
|
|
677
|
-
* @param host - the host element
|
|
678
|
-
* @param options - provisioning options
|
|
679
|
-
* @param options.entries - list of service entries to bind to the container
|
|
680
|
-
* @param options.into - target IoC context; if omitted, uses the nearest provider context
|
|
681
|
-
* @param options.activate - list of service identifiers to activate immediately after binding
|
|
682
|
-
* @param options.seeds - seed data applied before binding
|
|
683
|
-
*/
|
|
684
|
-
function InjectablesProviderController(host, options) {
|
|
685
|
-
var _this = this;
|
|
686
|
-
var _a, _b, _c;
|
|
687
|
-
this.host = host;
|
|
688
|
-
/**
|
|
689
|
-
* Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
|
|
690
|
-
*/
|
|
691
|
-
this.boundContext = null;
|
|
692
|
-
this.host.addController(this);
|
|
693
|
-
this.entries = options.entries;
|
|
694
|
-
this.activate = (_a = options.activate) !== null && _a !== void 0 ? _a : null;
|
|
695
|
-
this.seeds = (_b = options.seeds) !== null && _b !== void 0 ? _b : null;
|
|
696
|
-
this.into = (_c = options.into) !== null && _c !== void 0 ? _c : null;
|
|
697
|
-
if (!this.into) {
|
|
698
|
-
// subscribe: false — binding happens once per connect, not on every revision update.
|
|
699
|
-
this.consumer = new context.ContextConsumer(host, {
|
|
700
|
-
context: ContainerContext,
|
|
701
|
-
subscribe: false,
|
|
702
|
-
callback: function (context) {
|
|
703
|
-
if (!host.isConnected) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
_this.bind(context);
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
InjectablesProviderController.prototype.hostConnected = function () {
|
|
712
|
-
var _a;
|
|
713
|
-
if (!this.into) {
|
|
714
|
-
// ContextConsumer with subscribe:false only invokes the user callback once (provided flag stays true
|
|
715
|
-
// after disconnect). On reconnect we fall back to the cached consumer.value so bind() still fires.
|
|
716
|
-
if ((_a = this.consumer) === null || _a === void 0 ? void 0 : _a.value) {
|
|
717
|
-
this.bind(this.consumer.value);
|
|
718
|
-
}
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
var context = typeof this.into === "function" ? this.into() : this.into;
|
|
722
|
-
if (!context) {
|
|
723
|
-
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "InjectablesProviderController: the 'into' option resolved to null or undefined. " + "Ensure the value or resolver function returns a valid IocContext.");
|
|
724
|
-
}
|
|
725
|
-
this.bind(context);
|
|
726
|
-
};
|
|
727
|
-
InjectablesProviderController.prototype.hostDisconnected = function () {
|
|
728
|
-
if (!this.boundContext) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
this.unbind(this.boundContext);
|
|
732
|
-
};
|
|
733
|
-
InjectablesProviderController.prototype.bind = function (context) {
|
|
734
|
-
if (this.boundContext) {
|
|
735
|
-
// Re-binding without unbinding first would leave stale entries; unbind the previous context.
|
|
736
|
-
this.unbind(this.boundContext);
|
|
737
|
-
}
|
|
738
|
-
this.boundContext = context;
|
|
739
|
-
// Seeds must be applied before binding so @Inject(SEEDS_TOKEN) resolves during activation.
|
|
740
|
-
if (this.seeds) {
|
|
741
|
-
core.applySeeds(context.container, this.seeds);
|
|
742
|
-
}
|
|
743
|
-
for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
|
|
744
|
-
var entry = _a[_i];
|
|
745
|
-
core.bindEntry(context.container, entry);
|
|
746
|
-
}
|
|
747
|
-
if (this.activate) {
|
|
748
|
-
for (var _b = 0, _c = this.activate; _b < _c.length; _b++) {
|
|
749
|
-
var token = _c[_b];
|
|
750
|
-
context.container.get(token);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
InjectablesProviderController.prototype.unbind = function (context) {
|
|
755
|
-
for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
|
|
756
|
-
var entry = _a[_i];
|
|
757
|
-
var token = core.getEntryToken(entry);
|
|
758
|
-
if (context.container.isBound(token)) {
|
|
759
|
-
context.container.unbind(token);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
if (this.seeds) {
|
|
763
|
-
core.unapplySeeds(context.container, this.seeds);
|
|
764
|
-
}
|
|
765
|
-
this.boundContext = null;
|
|
766
|
-
};
|
|
767
|
-
return InjectablesProviderController;
|
|
768
|
-
}();
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
|
|
772
|
-
*
|
|
773
|
-
* Entries are bound when the host connects and unbound when it disconnects.
|
|
774
|
-
* The decorated accessor or property holds the resulting {@link InjectablesProviderController} instance.
|
|
775
|
-
*
|
|
776
|
-
* @group provision
|
|
777
|
-
*
|
|
778
|
-
* @param options - provisioning options
|
|
779
|
-
* @returns injectables provider decorator instance
|
|
846
|
+
* @param options - Provisioning options.
|
|
847
|
+
* @param options.options - Child-container creation options.
|
|
848
|
+
* @returns An instance of {@link SubContainerProviderDecorator}.
|
|
780
849
|
*
|
|
781
850
|
* @example
|
|
782
851
|
* ```typescript
|
|
783
852
|
* class MyComponent extends LitElement {
|
|
784
|
-
* @
|
|
785
|
-
*
|
|
853
|
+
* @subContainerProvide({
|
|
854
|
+
* options: {
|
|
855
|
+
* entries: [AuthService, UserService],
|
|
856
|
+
* activate: [AuthService],
|
|
857
|
+
* },
|
|
858
|
+
* })
|
|
859
|
+
* public containerProvider!: SubContainerProvider<MyComponent>;
|
|
786
860
|
* }
|
|
787
861
|
* ```
|
|
788
862
|
*/
|
|
789
|
-
function
|
|
863
|
+
function subContainerProvide(options) {
|
|
790
864
|
return function (protoOrTarget, nameOrContext) {
|
|
791
865
|
if (typeof nameOrContext === "object") {
|
|
792
866
|
// Standard decorators:
|
|
793
867
|
nameOrContext.addInitializer(function () {
|
|
794
|
-
protoOrTarget.set.call(this, new
|
|
868
|
+
protoOrTarget.set.call(this, new SubContainerProvider(this, options));
|
|
795
869
|
});
|
|
796
870
|
} else {
|
|
797
|
-
var
|
|
871
|
+
var provider_1;
|
|
798
872
|
protoOrTarget.constructor.addInitializer(function (element) {
|
|
799
|
-
|
|
873
|
+
provider_1 = new SubContainerProvider(element, options);
|
|
800
874
|
});
|
|
801
875
|
return {
|
|
802
876
|
get: function () {
|
|
803
|
-
return
|
|
877
|
+
return provider_1;
|
|
804
878
|
},
|
|
805
879
|
set: function () {},
|
|
806
880
|
configurable: true,
|
|
@@ -811,75 +885,93 @@ function injectablesProvide(options) {
|
|
|
811
885
|
}
|
|
812
886
|
|
|
813
887
|
/**
|
|
814
|
-
*
|
|
888
|
+
* Hook that provides a container to the host element and its children.
|
|
815
889
|
*
|
|
816
|
-
*
|
|
890
|
+
* @remarks
|
|
891
|
+
* Pass `container` to expose an external `Container` without taking
|
|
892
|
+
* ownership. Pass `options` to create a managed container during
|
|
893
|
+
* construction, activate configured entries on connect, destroy it on
|
|
894
|
+
* disconnect, and recreate it on reconnect.
|
|
817
895
|
*
|
|
818
|
-
* @group
|
|
896
|
+
* @group Provision
|
|
819
897
|
*
|
|
820
|
-
* @param host -
|
|
821
|
-
* @param options -
|
|
822
|
-
* @param options.
|
|
823
|
-
* @param options.
|
|
824
|
-
* @
|
|
825
|
-
* @param options.seeds - seed data applied before binding
|
|
826
|
-
* @returns the controller instance
|
|
898
|
+
* @param host - The host element.
|
|
899
|
+
* @param options - Provisioning options.
|
|
900
|
+
* @param options.container - External container instance to provide.
|
|
901
|
+
* @param options.options - Managed container creation options.
|
|
902
|
+
* @returns An instance of {@link ContainerProvider}.
|
|
827
903
|
*
|
|
828
904
|
* @example
|
|
829
905
|
* ```typescript
|
|
830
|
-
* class
|
|
831
|
-
* private
|
|
832
|
-
*
|
|
833
|
-
*
|
|
906
|
+
* class MyRootElement extends LitElement {
|
|
907
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, {
|
|
908
|
+
* options: {
|
|
909
|
+
* entries: [LoggerService],
|
|
910
|
+
* activate: [LoggerService],
|
|
911
|
+
* },
|
|
834
912
|
* });
|
|
835
913
|
* }
|
|
836
914
|
* ```
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```typescript
|
|
918
|
+
* class MyRootElement extends LitElement {
|
|
919
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
|
|
920
|
+
* }
|
|
921
|
+
* ```
|
|
837
922
|
*/
|
|
838
|
-
function
|
|
839
|
-
return new
|
|
923
|
+
function useContainerProvision(host, options) {
|
|
924
|
+
return new ContainerProvider(host, options);
|
|
840
925
|
}
|
|
841
926
|
|
|
842
927
|
/**
|
|
843
|
-
* Hook
|
|
928
|
+
* Hook that provides a managed child container for the host element's lifetime.
|
|
844
929
|
*
|
|
845
|
-
* @
|
|
930
|
+
* @remarks
|
|
931
|
+
* The child container is derived from the current parent
|
|
932
|
+
* {@link ContainerContext}, recreated when that parent context changes, and
|
|
933
|
+
* destroyed when the host disconnects.
|
|
846
934
|
*
|
|
847
|
-
* @
|
|
848
|
-
*
|
|
849
|
-
* @param
|
|
850
|
-
* @param options
|
|
851
|
-
* @
|
|
935
|
+
* @group Provision
|
|
936
|
+
*
|
|
937
|
+
* @param host - The host element.
|
|
938
|
+
* @param options - Provisioning options.
|
|
939
|
+
* @param options.options - Child-container creation options.
|
|
940
|
+
* @returns An instance of {@link SubContainerProvider}.
|
|
852
941
|
*
|
|
853
942
|
* @example
|
|
854
943
|
* ```typescript
|
|
855
|
-
* class
|
|
856
|
-
* private
|
|
944
|
+
* class MyComponent extends LitElement {
|
|
945
|
+
* private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
|
|
946
|
+
* options: {
|
|
947
|
+
* entries: [AuthService, UserService],
|
|
948
|
+
* },
|
|
949
|
+
* });
|
|
857
950
|
* }
|
|
858
951
|
* ```
|
|
859
952
|
*/
|
|
860
|
-
function
|
|
861
|
-
|
|
862
|
-
options = {};
|
|
863
|
-
}
|
|
864
|
-
return new IocProviderController(host, options);
|
|
953
|
+
function useSubContainerProvider(host, options) {
|
|
954
|
+
return new SubContainerProvider(host, options);
|
|
865
955
|
}
|
|
866
956
|
|
|
867
957
|
exports.ContainerContext = ContainerContext;
|
|
868
|
-
exports.
|
|
869
|
-
exports.IocProviderController = IocProviderController;
|
|
958
|
+
exports.ContainerProvider = ContainerProvider;
|
|
870
959
|
exports.OnCommandController = OnCommandController;
|
|
871
960
|
exports.OnEventController = OnEventController;
|
|
872
961
|
exports.OnQueryController = OnQueryController;
|
|
873
|
-
exports.
|
|
962
|
+
exports.SubContainerProvider = SubContainerProvider;
|
|
963
|
+
exports.containerProvide = containerProvide;
|
|
874
964
|
exports.injection = injection;
|
|
875
|
-
exports.iocProvide = iocProvide;
|
|
876
965
|
exports.onCommand = onCommand;
|
|
877
966
|
exports.onEvent = onEvent;
|
|
878
967
|
exports.onQuery = onQuery;
|
|
879
|
-
exports.
|
|
968
|
+
exports.subContainerProvide = subContainerProvide;
|
|
969
|
+
exports.useContainer = useContainer;
|
|
970
|
+
exports.useContainerProvision = useContainerProvision;
|
|
880
971
|
exports.useInjection = useInjection;
|
|
881
|
-
exports.useIocProvision = useIocProvision;
|
|
882
972
|
exports.useOnCommand = useOnCommand;
|
|
883
973
|
exports.useOnEvents = useOnEvents;
|
|
884
974
|
exports.useOnQuery = useOnQuery;
|
|
975
|
+
exports.useScope = useScope;
|
|
976
|
+
exports.useSubContainerProvider = useSubContainerProvider;
|
|
885
977
|
//# sourceMappingURL=index.js.map
|