@wirestate/lit 0.7.0-experimental.1 → 0.7.0-experimental.3
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 +8 -2
- package/README.md +49 -31
- package/cjs/development/index.js +420 -362
- 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 +19 -22
- package/esm/development/commands/on-command-controller.js.map +1 -1
- package/esm/development/commands/on-command.js +4 -9
- package/esm/development/commands/on-command.js.map +1 -1
- package/esm/development/commands/use-on-command.js +4 -3
- package/esm/development/commands/use-on-command.js.map +1 -1
- package/esm/development/consumption/injection.js +14 -13
- 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 +12 -10
- 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/error/error-code.js +1 -1
- package/esm/development/error/error-code.js.map +1 -1
- package/esm/development/events/on-event-controller.js +22 -26
- package/esm/development/events/on-event-controller.js.map +1 -1
- package/esm/development/events/on-event.js +5 -11
- package/esm/development/events/on-event.js.map +1 -1
- package/esm/development/events/use-on-events.js +5 -5
- package/esm/development/events/use-on-events.js.map +1 -1
- 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 +68 -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 +90 -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 +19 -22
- package/esm/development/queries/on-query-controller.js.map +1 -1
- package/esm/development/queries/on-query.js +4 -9
- package/esm/development/queries/on-query.js.map +1 -1
- package/esm/development/queries/use-on-query.js +4 -3
- package/esm/development/queries/use-on-query.js.map +1 -1
- 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 +1 -1
- package/esm/production/commands/on-command.js.map +1 -1
- package/esm/production/commands/use-on-command.js +1 -1
- package/esm/production/commands/use-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/error/error-code.js +1 -1
- package/esm/production/error/error-code.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 +1 -1
- package/esm/production/events/on-event.js.map +1 -1
- package/esm/production/events/use-on-events.js +1 -1
- package/esm/production/events/use-on-events.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 +1 -1
- package/esm/production/queries/on-query.js.map +1 -1
- package/esm/production/queries/use-on-query.js +1 -1
- package/esm/production/queries/use-on-query.js.map +1 -1
- package/index.d.ts +271 -176
- 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 -58
- package/esm/development/provision/ioc-provide.js.map +0 -1
- package/esm/development/provision/ioc-provider-controller.js +0 -75
- package/esm/development/provision/ioc-provider-controller.js.map +0 -1
- package/esm/development/provision/use-injectables-provider.js +0 -27
- package/esm/development/provision/use-injectables-provider.js.map +0 -1
- package/esm/development/provision/use-ioc-provision.js +0 -27
- 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
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
var context = require('@lit/context');
|
|
4
4
|
var core = require('@wirestate/core');
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Unique symbol used as a key for the IoC context.
|
|
9
8
|
*
|
|
10
9
|
* @group Context
|
|
11
10
|
*/
|
|
12
|
-
|
|
11
|
+
const CONTAINER_KEY = Symbol("ContainerContext");
|
|
13
12
|
/**
|
|
14
|
-
* Lit context object for providing and consuming the
|
|
13
|
+
* Lit context object for providing and consuming the container.
|
|
15
14
|
*
|
|
16
15
|
* @group Context
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
const ContainerContext = context.createContext(CONTAINER_KEY);
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Decorator to inject a service from the IoC container into a Lit element property.
|
|
@@ -50,31 +49,32 @@ var IocContextObject = context.createContext(IOC_CONTAINER_KEY);
|
|
|
50
49
|
* ```
|
|
51
50
|
*/
|
|
52
51
|
function injection(optionsOrInjectionId) {
|
|
53
|
-
|
|
52
|
+
const options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
|
|
54
53
|
injectionId: optionsOrInjectionId
|
|
55
54
|
};
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
return (protoOrTarget, nameOrContext) => {
|
|
56
|
+
const {
|
|
57
|
+
injectionId,
|
|
58
|
+
once
|
|
59
|
+
} = options;
|
|
59
60
|
// Standard decorators branch.
|
|
60
61
|
if (typeof nameOrContext === "object") {
|
|
61
62
|
nameOrContext.addInitializer(function () {
|
|
62
|
-
var _this = this;
|
|
63
63
|
new context.ContextConsumer(this, {
|
|
64
|
-
context:
|
|
65
|
-
callback:
|
|
66
|
-
protoOrTarget.set.call(
|
|
64
|
+
context: ContainerContext,
|
|
65
|
+
callback: container => {
|
|
66
|
+
protoOrTarget.set.call(this, container.get(injectionId));
|
|
67
67
|
},
|
|
68
68
|
subscribe: !once
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
} else {
|
|
72
72
|
// Experimental decorators branch.
|
|
73
|
-
protoOrTarget.constructor.addInitializer(
|
|
73
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
74
74
|
new context.ContextConsumer(element, {
|
|
75
|
-
context:
|
|
76
|
-
callback:
|
|
77
|
-
element[nameOrContext] =
|
|
75
|
+
context: ContainerContext,
|
|
76
|
+
callback: container => {
|
|
77
|
+
element[nameOrContext] = container.get(injectionId);
|
|
78
78
|
},
|
|
79
79
|
subscribe: !once
|
|
80
80
|
});
|
|
@@ -83,6 +83,41 @@ function injection(optionsOrInjectionId) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Hook (consumer) to access the active container from the nearest parent context.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* The returned value updates when the nearest provided container changes.
|
|
91
|
+
*
|
|
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
|
+
const current = {
|
|
110
|
+
value: null
|
|
111
|
+
};
|
|
112
|
+
new context.ContextConsumer(host, {
|
|
113
|
+
context: ContainerContext,
|
|
114
|
+
callback: container => {
|
|
115
|
+
current.value = container;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return current;
|
|
119
|
+
}
|
|
120
|
+
|
|
86
121
|
/**
|
|
87
122
|
* Hook (controller) to inject a service from the IoC container.
|
|
88
123
|
*
|
|
@@ -115,21 +150,61 @@ function injection(optionsOrInjectionId) {
|
|
|
115
150
|
* ```
|
|
116
151
|
*/
|
|
117
152
|
function useInjection(host, optionsOrInjectionId) {
|
|
118
|
-
|
|
153
|
+
const options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
|
|
119
154
|
injectionId: optionsOrInjectionId
|
|
120
155
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
156
|
+
const {
|
|
157
|
+
once,
|
|
158
|
+
injectionId,
|
|
159
|
+
value
|
|
160
|
+
} = options;
|
|
161
|
+
const current = {
|
|
125
162
|
value: value,
|
|
126
|
-
injectionId
|
|
163
|
+
injectionId
|
|
127
164
|
};
|
|
128
165
|
new context.ContextConsumer(host, {
|
|
129
|
-
context:
|
|
166
|
+
context: ContainerContext,
|
|
130
167
|
subscribe: !once,
|
|
131
|
-
callback:
|
|
132
|
-
current.value =
|
|
168
|
+
callback: container => {
|
|
169
|
+
current.value = container.get(injectionId);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return current;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* The returned value updates when the nearest provided container changes.
|
|
180
|
+
*
|
|
181
|
+
* @group Consumption
|
|
182
|
+
*
|
|
183
|
+
* @param host - The host element.
|
|
184
|
+
* @returns An instance of {@link UseScopeValue}.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* class MyElement extends LitElement {
|
|
189
|
+
* private scope: UseScopeValue = useScope(this);
|
|
190
|
+
*
|
|
191
|
+
* public connectedCallback(): void {
|
|
192
|
+
* super.connectedCallback();
|
|
193
|
+
* this.scope.value.emitEvent("UI_READY");
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
function useScope(host) {
|
|
199
|
+
const current = {
|
|
200
|
+
value: undefined,
|
|
201
|
+
injectionId: core.WireScope
|
|
202
|
+
};
|
|
203
|
+
new context.ContextConsumer(host, {
|
|
204
|
+
context: ContainerContext,
|
|
205
|
+
subscribe: true,
|
|
206
|
+
callback: container => {
|
|
207
|
+
current.value = container.get(core.WireScope);
|
|
133
208
|
}
|
|
134
209
|
});
|
|
135
210
|
return current;
|
|
@@ -144,49 +219,46 @@ function useInjection(host, optionsOrInjectionId) {
|
|
|
144
219
|
*
|
|
145
220
|
* @group Commands
|
|
146
221
|
*/
|
|
147
|
-
|
|
222
|
+
class OnCommandController {
|
|
223
|
+
bus = null;
|
|
224
|
+
unregister = null;
|
|
148
225
|
/**
|
|
149
226
|
* @param host - The host element.
|
|
150
227
|
* @param type - Unique identifier of the command to handle.
|
|
151
228
|
* @param handler - The command handler function.
|
|
152
229
|
*/
|
|
153
|
-
|
|
154
|
-
var _this = this;
|
|
155
|
-
this.bus = null;
|
|
156
|
-
this.unregister = null;
|
|
230
|
+
constructor(host, type, handler) {
|
|
157
231
|
host.addController(this);
|
|
158
232
|
this.type = type;
|
|
159
233
|
this.handler = handler;
|
|
160
234
|
new context.ContextConsumer(host, {
|
|
161
|
-
context:
|
|
235
|
+
context: ContainerContext,
|
|
162
236
|
subscribe: true,
|
|
163
|
-
callback:
|
|
164
|
-
|
|
237
|
+
callback: container => {
|
|
238
|
+
this.bus = container.get(core.CommandBus);
|
|
165
239
|
if (host.isConnected) {
|
|
166
|
-
|
|
240
|
+
this.reregister();
|
|
167
241
|
}
|
|
168
242
|
}
|
|
169
243
|
});
|
|
170
244
|
}
|
|
171
|
-
|
|
245
|
+
hostConnected() {
|
|
172
246
|
this.reregister();
|
|
173
|
-
}
|
|
174
|
-
|
|
247
|
+
}
|
|
248
|
+
hostDisconnected() {
|
|
175
249
|
this.cleanup();
|
|
176
|
-
}
|
|
177
|
-
|
|
250
|
+
}
|
|
251
|
+
reregister() {
|
|
178
252
|
this.cleanup();
|
|
179
253
|
if (this.bus) {
|
|
180
254
|
this.unregister = this.bus.register(this.type, this.handler);
|
|
181
255
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
(_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
256
|
+
}
|
|
257
|
+
cleanup() {
|
|
258
|
+
this.unregister?.();
|
|
186
259
|
this.unregister = null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
}();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
190
262
|
|
|
191
263
|
/**
|
|
192
264
|
* Decorator for Lit element methods that handle a specific command.
|
|
@@ -210,21 +282,16 @@ var OnCommandController = /** @class */function () {
|
|
|
210
282
|
* ```
|
|
211
283
|
*/
|
|
212
284
|
function onCommand(type) {
|
|
213
|
-
return
|
|
285
|
+
return (protoOrTarget, nameOrContext) => {
|
|
214
286
|
if (typeof nameOrContext === "object") {
|
|
215
287
|
// Standard decorators:
|
|
216
288
|
nameOrContext.addInitializer(function () {
|
|
217
|
-
|
|
218
|
-
new OnCommandController(this, type, function (data) {
|
|
219
|
-
return _this[nameOrContext.name](data);
|
|
220
|
-
});
|
|
289
|
+
new OnCommandController(this, type, data => this[nameOrContext.name](data));
|
|
221
290
|
});
|
|
222
291
|
} else {
|
|
223
292
|
// Experimental legacy decorators:
|
|
224
|
-
protoOrTarget.constructor.addInitializer(
|
|
225
|
-
new OnCommandController(element, type,
|
|
226
|
-
return element[nameOrContext](data);
|
|
227
|
-
});
|
|
293
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
294
|
+
new OnCommandController(element, type, data => element[nameOrContext](data));
|
|
228
295
|
});
|
|
229
296
|
}
|
|
230
297
|
};
|
|
@@ -251,9 +318,10 @@ function onCommand(type) {
|
|
|
251
318
|
* }
|
|
252
319
|
* ```
|
|
253
320
|
*/
|
|
254
|
-
function useOnCommand(host,
|
|
255
|
-
|
|
256
|
-
|
|
321
|
+
function useOnCommand(host, {
|
|
322
|
+
type,
|
|
323
|
+
handler
|
|
324
|
+
}) {
|
|
257
325
|
return new OnCommandController(host, type, handler);
|
|
258
326
|
}
|
|
259
327
|
|
|
@@ -266,58 +334,54 @@ function useOnCommand(host, _a) {
|
|
|
266
334
|
*
|
|
267
335
|
* @group Events
|
|
268
336
|
*/
|
|
269
|
-
|
|
337
|
+
class OnEventController {
|
|
338
|
+
bus = null;
|
|
339
|
+
unsubscriber = null;
|
|
270
340
|
/**
|
|
271
341
|
* @param host - The host element.
|
|
272
342
|
* @param types - Event types to listen for. If null, all events will be handled.
|
|
273
343
|
* @param handler - The event handler function.
|
|
274
344
|
*/
|
|
275
|
-
|
|
276
|
-
var _this = this;
|
|
277
|
-
this.bus = null;
|
|
278
|
-
this.unsubscriber = null;
|
|
345
|
+
constructor(host, types, handler) {
|
|
279
346
|
host.addController(this);
|
|
280
347
|
this.types = types;
|
|
281
348
|
this.handler = handler;
|
|
282
349
|
new context.ContextConsumer(host, {
|
|
283
|
-
context:
|
|
350
|
+
context: ContainerContext,
|
|
284
351
|
subscribe: true,
|
|
285
|
-
callback:
|
|
286
|
-
|
|
352
|
+
callback: container => {
|
|
353
|
+
this.bus = container.get(core.EventBus);
|
|
287
354
|
if (host.isConnected) {
|
|
288
|
-
|
|
355
|
+
this.resubscribe();
|
|
289
356
|
}
|
|
290
357
|
}
|
|
291
358
|
});
|
|
292
359
|
}
|
|
293
|
-
|
|
360
|
+
hostConnected() {
|
|
294
361
|
this.resubscribe();
|
|
295
|
-
}
|
|
296
|
-
|
|
362
|
+
}
|
|
363
|
+
hostDisconnected() {
|
|
297
364
|
this.cleanup();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
var _this = this;
|
|
365
|
+
}
|
|
366
|
+
resubscribe() {
|
|
301
367
|
this.cleanup();
|
|
302
368
|
if (this.bus) {
|
|
303
369
|
if (this.types === null) {
|
|
304
370
|
this.unsubscriber = this.bus.subscribe(this.handler);
|
|
305
371
|
} else {
|
|
306
|
-
this.unsubscriber = this.bus.subscribe(
|
|
307
|
-
if (
|
|
308
|
-
|
|
372
|
+
this.unsubscriber = this.bus.subscribe(event => {
|
|
373
|
+
if (this.types.includes(event.type)) {
|
|
374
|
+
this.handler(event);
|
|
309
375
|
}
|
|
310
376
|
});
|
|
311
377
|
}
|
|
312
378
|
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
(_a = this.unsubscriber) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
379
|
+
}
|
|
380
|
+
cleanup() {
|
|
381
|
+
this.unsubscriber?.();
|
|
317
382
|
this.unsubscriber = null;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
}();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
321
385
|
|
|
322
386
|
/**
|
|
323
387
|
* Decorator for Lit element methods that handle events from the event bus.
|
|
@@ -361,22 +425,17 @@ var OnEventController = /** @class */function () {
|
|
|
361
425
|
* ```
|
|
362
426
|
*/
|
|
363
427
|
function onEvent(types) {
|
|
364
|
-
|
|
365
|
-
return
|
|
428
|
+
const normalized = types === undefined ? null : Array.isArray(types) ? [...types] : [types];
|
|
429
|
+
return (protoOrTarget, nameOrContext) => {
|
|
366
430
|
if (typeof nameOrContext === "object") {
|
|
367
431
|
// Standard decorators:
|
|
368
432
|
nameOrContext.addInitializer(function () {
|
|
369
|
-
|
|
370
|
-
new OnEventController(this, normalized, function (event) {
|
|
371
|
-
return _this[nameOrContext.name](event);
|
|
372
|
-
});
|
|
433
|
+
new OnEventController(this, normalized, event => this[nameOrContext.name](event));
|
|
373
434
|
});
|
|
374
435
|
} else {
|
|
375
436
|
// Experimental legacy decorators:
|
|
376
|
-
protoOrTarget.constructor.addInitializer(
|
|
377
|
-
new OnEventController(element, normalized,
|
|
378
|
-
return element[nameOrContext](event);
|
|
379
|
-
});
|
|
437
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
438
|
+
new OnEventController(element, normalized, event => element[nameOrContext](event));
|
|
380
439
|
});
|
|
381
440
|
}
|
|
382
441
|
};
|
|
@@ -412,10 +471,11 @@ function onEvent(types) {
|
|
|
412
471
|
* }
|
|
413
472
|
* ```
|
|
414
473
|
*/
|
|
415
|
-
function useOnEvents(host,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
474
|
+
function useOnEvents(host, {
|
|
475
|
+
types,
|
|
476
|
+
handler
|
|
477
|
+
}) {
|
|
478
|
+
const normalized = types ? Array.isArray(types) ? [...types] : [types] : null;
|
|
419
479
|
return new OnEventController(host, normalized, handler);
|
|
420
480
|
}
|
|
421
481
|
|
|
@@ -428,49 +488,46 @@ function useOnEvents(host, _a) {
|
|
|
428
488
|
*
|
|
429
489
|
* @group Queries
|
|
430
490
|
*/
|
|
431
|
-
|
|
491
|
+
class OnQueryController {
|
|
492
|
+
bus = null;
|
|
493
|
+
unregister = null;
|
|
432
494
|
/**
|
|
433
495
|
* @param host - The host element.
|
|
434
496
|
* @param type - Unique identifier of the query to handle.
|
|
435
497
|
* @param handler - The query handler function.
|
|
436
498
|
*/
|
|
437
|
-
|
|
438
|
-
var _this = this;
|
|
439
|
-
this.bus = null;
|
|
440
|
-
this.unregister = null;
|
|
499
|
+
constructor(host, type, handler) {
|
|
441
500
|
host.addController(this);
|
|
442
501
|
this.type = type;
|
|
443
502
|
this.handler = handler;
|
|
444
503
|
new context.ContextConsumer(host, {
|
|
445
|
-
context:
|
|
504
|
+
context: ContainerContext,
|
|
446
505
|
subscribe: true,
|
|
447
|
-
callback:
|
|
448
|
-
|
|
506
|
+
callback: container => {
|
|
507
|
+
this.bus = container.get(core.QueryBus);
|
|
449
508
|
if (host.isConnected) {
|
|
450
|
-
|
|
509
|
+
this.reregister();
|
|
451
510
|
}
|
|
452
511
|
}
|
|
453
512
|
});
|
|
454
513
|
}
|
|
455
|
-
|
|
514
|
+
hostConnected() {
|
|
456
515
|
this.reregister();
|
|
457
|
-
}
|
|
458
|
-
|
|
516
|
+
}
|
|
517
|
+
hostDisconnected() {
|
|
459
518
|
this.cleanup();
|
|
460
|
-
}
|
|
461
|
-
|
|
519
|
+
}
|
|
520
|
+
reregister() {
|
|
462
521
|
this.cleanup();
|
|
463
522
|
if (this.bus) {
|
|
464
523
|
this.unregister = this.bus.register(this.type, this.handler);
|
|
465
524
|
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
(_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
525
|
+
}
|
|
526
|
+
cleanup() {
|
|
527
|
+
this.unregister?.();
|
|
470
528
|
this.unregister = null;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
}();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
474
531
|
|
|
475
532
|
/**
|
|
476
533
|
* Decorator for Lit element methods that handle a specific query.
|
|
@@ -494,21 +551,16 @@ var OnQueryController = /** @class */function () {
|
|
|
494
551
|
* ```
|
|
495
552
|
*/
|
|
496
553
|
function onQuery(type) {
|
|
497
|
-
return
|
|
554
|
+
return (protoOrTarget, nameOrContext) => {
|
|
498
555
|
if (typeof nameOrContext === "object") {
|
|
499
556
|
// Standard decorators:
|
|
500
557
|
nameOrContext.addInitializer(function () {
|
|
501
|
-
|
|
502
|
-
new OnQueryController(this, type, function (data) {
|
|
503
|
-
return _this[nameOrContext.name](data);
|
|
504
|
-
});
|
|
558
|
+
new OnQueryController(this, type, data => this[nameOrContext.name](data));
|
|
505
559
|
});
|
|
506
560
|
} else {
|
|
507
561
|
// Experimental legacy decorators:
|
|
508
|
-
protoOrTarget.constructor.addInitializer(
|
|
509
|
-
new OnQueryController(element, type,
|
|
510
|
-
return element[nameOrContext](data);
|
|
511
|
-
});
|
|
562
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
563
|
+
new OnQueryController(element, type, data => element[nameOrContext](data));
|
|
512
564
|
});
|
|
513
565
|
}
|
|
514
566
|
};
|
|
@@ -535,128 +587,217 @@ function onQuery(type) {
|
|
|
535
587
|
* }
|
|
536
588
|
* ```
|
|
537
589
|
*/
|
|
538
|
-
function useOnQuery(host,
|
|
539
|
-
|
|
540
|
-
|
|
590
|
+
function useOnQuery(host, {
|
|
591
|
+
type,
|
|
592
|
+
handler
|
|
593
|
+
}) {
|
|
541
594
|
return new OnQueryController(host, type, handler);
|
|
542
595
|
}
|
|
543
596
|
|
|
597
|
+
const ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
598
|
+
|
|
544
599
|
/**
|
|
545
|
-
*
|
|
600
|
+
* Provider that exposes an IoC container context to the host element and its children.
|
|
546
601
|
*
|
|
547
602
|
* @remarks
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
603
|
+
* The provider supports two modes:
|
|
604
|
+
*
|
|
605
|
+
* - External mode: `container` is an existing {@link Container}. The
|
|
606
|
+
* provider passes it through context and does not alter its lifecycle.
|
|
607
|
+
* - Managed mode: `options` is {@link CreateContainerOptions}. The provider
|
|
608
|
+
* creates a container during construction without eager activation,
|
|
609
|
+
* activates configured entries when the host connects, disposes the
|
|
610
|
+
* container when the host disconnects, and recreates it on reconnect.
|
|
551
611
|
*
|
|
552
612
|
* @group Provision
|
|
553
613
|
*/
|
|
554
|
-
|
|
614
|
+
class ContainerProvider extends context.ContextProvider {
|
|
615
|
+
destroyed = false;
|
|
555
616
|
/**
|
|
556
617
|
* @param host - The host element.
|
|
557
618
|
* @param options - Provisioning options.
|
|
558
|
-
* @param options.container -
|
|
559
|
-
* @param options.
|
|
619
|
+
* @param options.container - External container instance to provide.
|
|
620
|
+
* @param options.options - Managed container creation options.
|
|
560
621
|
*/
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
container
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
622
|
+
constructor(host, options) {
|
|
623
|
+
if (!options.container && !options.options) {
|
|
624
|
+
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
|
|
625
|
+
} else if (options.container && options.options) {
|
|
626
|
+
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
|
|
627
|
+
}
|
|
628
|
+
super(host, {
|
|
629
|
+
context: ContainerContext,
|
|
630
|
+
initialValue: options.container ? options.container : core.createContainer({
|
|
631
|
+
...options.options,
|
|
632
|
+
activate: []
|
|
633
|
+
})
|
|
634
|
+
});
|
|
635
|
+
this.options = options.options;
|
|
636
|
+
}
|
|
637
|
+
hostConnected() {
|
|
638
|
+
if (this.options) {
|
|
639
|
+
if (this.destroyed) {
|
|
640
|
+
this.value = core.createContainer(this.options);
|
|
641
|
+
this.destroyed = false;
|
|
642
|
+
} else {
|
|
643
|
+
if (this.options?.activate) {
|
|
644
|
+
for (const entry of this.options.activate) {
|
|
645
|
+
this.value.get(entry);
|
|
646
|
+
}
|
|
578
647
|
}
|
|
579
648
|
}
|
|
580
|
-
}
|
|
649
|
+
}
|
|
650
|
+
super.hostConnected();
|
|
581
651
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
get: function () {
|
|
587
|
-
return this.provider.value;
|
|
588
|
-
},
|
|
589
|
-
enumerable: false,
|
|
590
|
-
configurable: true
|
|
591
|
-
});
|
|
592
|
-
IocProviderController.prototype.hostConnected = function () {
|
|
593
|
-
if (this.seed) {
|
|
594
|
-
core.applySharedSeed(this.container, this.seed);
|
|
652
|
+
hostDisconnected() {
|
|
653
|
+
if (this.options) {
|
|
654
|
+
this.value.unbindAll();
|
|
655
|
+
this.destroyed = true;
|
|
595
656
|
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Provider that exposes a managed child container for the host element's lifetime.
|
|
662
|
+
*
|
|
663
|
+
* @remarks
|
|
664
|
+
* The provider always owns a child container derived from the nearest parent
|
|
665
|
+
* {@link ContainerContext}. When connected, it creates a child container using
|
|
666
|
+
* the latest parent context, provides it to descendants, destroys it when the
|
|
667
|
+
* host disconnects, and replaces it whenever the parent container changes.
|
|
668
|
+
*
|
|
669
|
+
* @group Provision
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```typescript
|
|
673
|
+
* class MyComponent extends LitElement {
|
|
674
|
+
* private container = new SubContainerProvider(this, {
|
|
675
|
+
* options: {
|
|
676
|
+
* entries: [AuthService, UserService],
|
|
677
|
+
* activate: [AuthService],
|
|
678
|
+
* seeds: [[AuthService, { role: "admin" }]],
|
|
679
|
+
* },
|
|
680
|
+
* });
|
|
681
|
+
* }
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
class SubContainerProvider extends context.ContextProvider {
|
|
685
|
+
parent = null;
|
|
686
|
+
destroyed = true;
|
|
687
|
+
/**
|
|
688
|
+
* @param host - The host element.
|
|
689
|
+
* @param options - Provisioning options, including child entries, eager activations, and seeds.
|
|
690
|
+
*/
|
|
691
|
+
constructor(host, options) {
|
|
692
|
+
super(host, {
|
|
693
|
+
context: ContainerContext
|
|
694
|
+
});
|
|
695
|
+
this.options = options.options;
|
|
696
|
+
this.consumer = new context.ContextConsumer(host, {
|
|
697
|
+
context: ContainerContext,
|
|
698
|
+
subscribe: true,
|
|
699
|
+
callback: context => {
|
|
700
|
+
const previousParent = this.parent;
|
|
701
|
+
this.parent = context;
|
|
702
|
+
if (host.isConnected) {
|
|
703
|
+
if (this.destroyed || !this.value || previousParent !== context) {
|
|
704
|
+
this.destroyContainer();
|
|
705
|
+
this.createContainer();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
606
708
|
}
|
|
607
709
|
});
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
710
|
+
}
|
|
711
|
+
hostConnected() {
|
|
712
|
+
if (this.parent && (this.destroyed || !this.value)) {
|
|
713
|
+
this.destroyContainer();
|
|
714
|
+
this.createContainer();
|
|
715
|
+
}
|
|
716
|
+
super.hostConnected();
|
|
717
|
+
}
|
|
718
|
+
hostDisconnected() {
|
|
719
|
+
this.destroyContainer();
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Replaces the currently provided child container with a new one derived
|
|
723
|
+
* from the latest parent context.
|
|
724
|
+
*/
|
|
725
|
+
createContainer() {
|
|
726
|
+
const container = core.createContainer({
|
|
727
|
+
...this.options,
|
|
728
|
+
parent: this.parent
|
|
729
|
+
});
|
|
730
|
+
this.destroyed = false;
|
|
731
|
+
this.value = container;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Destroys the currently provided child container.
|
|
735
|
+
*/
|
|
736
|
+
destroyContainer() {
|
|
737
|
+
if (this.value && !this.destroyed) {
|
|
738
|
+
this.value.unbindAll();
|
|
739
|
+
this.destroyed = true;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
612
743
|
|
|
613
744
|
/**
|
|
614
745
|
* Decorator that provides an IoC container to child components.
|
|
615
746
|
*
|
|
616
747
|
* @remarks
|
|
617
|
-
* The container is provided via Lit context.
|
|
748
|
+
* The container is provided via Lit context.
|
|
749
|
+
*
|
|
750
|
+
* - Pass `container` to expose an external container without taking
|
|
751
|
+
* ownership.
|
|
752
|
+
* - Pass `options` to create a managed container during construction,
|
|
753
|
+
* activate configured entries on connect, destroy it on disconnect, and
|
|
754
|
+
* recreate it on reconnect.
|
|
618
755
|
*
|
|
619
756
|
* @group Provision
|
|
620
757
|
*
|
|
621
758
|
* @param options - Provisioning options.
|
|
622
|
-
* @param options.container -
|
|
623
|
-
* @param options.
|
|
624
|
-
* @returns An instance of {@link
|
|
759
|
+
* @param options.container - External container instance to provide.
|
|
760
|
+
* @param options.options - Managed container creation options.
|
|
761
|
+
* @returns An instance of {@link ContainerProviderDecorator}.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```typescript
|
|
765
|
+
* class MyRootElement extends LitElement {
|
|
766
|
+
* @containerProvide({
|
|
767
|
+
* options: {
|
|
768
|
+
* seed: { someData: "value" },
|
|
769
|
+
* entries: [LoggerService],
|
|
770
|
+
* },
|
|
771
|
+
* })
|
|
772
|
+
* private containerProvider!: ContainerProvider;
|
|
773
|
+
* }
|
|
774
|
+
* ```
|
|
625
775
|
*
|
|
626
776
|
* @example
|
|
627
777
|
* ```typescript
|
|
628
778
|
* class MyRootElement extends LitElement {
|
|
629
|
-
* @
|
|
630
|
-
* private
|
|
779
|
+
* @containerProvide({ container: container })
|
|
780
|
+
* private containerProvider!: ContainerProvider;
|
|
631
781
|
* }
|
|
632
782
|
* ```
|
|
633
783
|
*/
|
|
634
|
-
function
|
|
635
|
-
|
|
636
|
-
container = _b.container,
|
|
637
|
-
seed = _b.seed;
|
|
638
|
-
return function (protoOrTarget, nameOrContext) {
|
|
784
|
+
function containerProvide(options) {
|
|
785
|
+
return (protoOrTarget, nameOrContext) => {
|
|
639
786
|
if (typeof nameOrContext === "object") {
|
|
640
787
|
// Standard decorators:
|
|
641
788
|
nameOrContext.addInitializer(function () {
|
|
642
|
-
protoOrTarget.set.call(this, new
|
|
643
|
-
container: container,
|
|
644
|
-
seed: seed
|
|
645
|
-
}));
|
|
789
|
+
protoOrTarget.set.call(this, new ContainerProvider(this, options));
|
|
646
790
|
});
|
|
647
791
|
} else {
|
|
648
|
-
|
|
649
|
-
protoOrTarget.constructor.addInitializer(
|
|
650
|
-
|
|
651
|
-
container: container,
|
|
652
|
-
seed: seed
|
|
653
|
-
});
|
|
792
|
+
let controller;
|
|
793
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
794
|
+
controller = new ContainerProvider(element, options);
|
|
654
795
|
});
|
|
655
796
|
return {
|
|
656
|
-
get
|
|
657
|
-
return
|
|
797
|
+
get() {
|
|
798
|
+
return controller;
|
|
658
799
|
},
|
|
659
|
-
set
|
|
800
|
+
set() {},
|
|
660
801
|
configurable: true,
|
|
661
802
|
enumerable: true
|
|
662
803
|
};
|
|
@@ -664,160 +805,51 @@ function iocProvide(_a) {
|
|
|
664
805
|
};
|
|
665
806
|
}
|
|
666
807
|
|
|
667
|
-
var ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Controller that binds injectables to an IoC container for the host element's lifetime.
|
|
671
|
-
*
|
|
672
|
-
* @remarks
|
|
673
|
-
* Entries are bound when the host connects and unbound when it disconnects.
|
|
674
|
-
* If no `into` context is provided, it uses the nearest {@link IocProviderController}.
|
|
675
|
-
* Seeds are applied before entries are bound.
|
|
676
|
-
*
|
|
677
|
-
* @group Provision
|
|
678
|
-
*
|
|
679
|
-
* @example
|
|
680
|
-
* ```typescript
|
|
681
|
-
* class MyComponent extends LitElement {
|
|
682
|
-
* private services = new InjectablesProviderController(this, {
|
|
683
|
-
* entries: [AuthService, UserService],
|
|
684
|
-
* activate: [AuthService],
|
|
685
|
-
* seeds: [[AuthService, { role: "admin" }]],
|
|
686
|
-
* });
|
|
687
|
-
* }
|
|
688
|
-
* ```
|
|
689
|
-
*/
|
|
690
|
-
var InjectablesProviderController = /** @class */function () {
|
|
691
|
-
/**
|
|
692
|
-
* @param host - The host element.
|
|
693
|
-
* @param options - Provisioning options.
|
|
694
|
-
* @param options.entries - List of service entries to bind to the container.
|
|
695
|
-
* @param options.into - Target IoC context; if omitted, uses the nearest provider context.
|
|
696
|
-
* @param options.activate - List of service identifiers to activate immediately after binding.
|
|
697
|
-
* @param options.seeds - Seed data applied before binding.
|
|
698
|
-
*/
|
|
699
|
-
function InjectablesProviderController(host, options) {
|
|
700
|
-
var _this = this;
|
|
701
|
-
var _a, _b, _c;
|
|
702
|
-
this.host = host;
|
|
703
|
-
/**
|
|
704
|
-
* Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
|
|
705
|
-
*/
|
|
706
|
-
this.boundContext = null;
|
|
707
|
-
this.host.addController(this);
|
|
708
|
-
this.entries = options.entries;
|
|
709
|
-
this.activate = (_a = options.activate) !== null && _a !== void 0 ? _a : null;
|
|
710
|
-
this.seeds = (_b = options.seeds) !== null && _b !== void 0 ? _b : null;
|
|
711
|
-
this.into = (_c = options.into) !== null && _c !== void 0 ? _c : null;
|
|
712
|
-
if (!this.into) {
|
|
713
|
-
// subscribe: false — binding happens once per connect, not on every revision update.
|
|
714
|
-
this.consumer = new context.ContextConsumer(host, {
|
|
715
|
-
context: IocContextObject,
|
|
716
|
-
subscribe: false,
|
|
717
|
-
callback: function (context) {
|
|
718
|
-
if (!host.isConnected) {
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
_this.bind(context);
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
InjectablesProviderController.prototype.hostConnected = function () {
|
|
727
|
-
var _a;
|
|
728
|
-
if (!this.into) {
|
|
729
|
-
// ContextConsumer with subscribe:false only invokes the user callback once (provided flag stays true
|
|
730
|
-
// after disconnect). On reconnect we fall back to the cached consumer.value so bind() still fires.
|
|
731
|
-
if ((_a = this.consumer) === null || _a === void 0 ? void 0 : _a.value) {
|
|
732
|
-
this.bind(this.consumer.value);
|
|
733
|
-
}
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
var context = typeof this.into === "function" ? this.into() : this.into;
|
|
737
|
-
if (!context) {
|
|
738
|
-
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.");
|
|
739
|
-
}
|
|
740
|
-
this.bind(context);
|
|
741
|
-
};
|
|
742
|
-
InjectablesProviderController.prototype.hostDisconnected = function () {
|
|
743
|
-
if (!this.boundContext) {
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
this.unbind(this.boundContext);
|
|
747
|
-
};
|
|
748
|
-
InjectablesProviderController.prototype.bind = function (context) {
|
|
749
|
-
if (this.boundContext) {
|
|
750
|
-
// Re-binding without unbinding first would leave stale entries; unbind the previous context.
|
|
751
|
-
this.unbind(this.boundContext);
|
|
752
|
-
}
|
|
753
|
-
this.boundContext = context;
|
|
754
|
-
// Seeds must be applied before binding so @Inject(SEEDS_TOKEN) resolves during activation.
|
|
755
|
-
if (this.seeds) {
|
|
756
|
-
core.applySeeds(context.container, this.seeds);
|
|
757
|
-
}
|
|
758
|
-
for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
|
|
759
|
-
var entry = _a[_i];
|
|
760
|
-
core.bindEntry(context.container, entry);
|
|
761
|
-
}
|
|
762
|
-
if (this.activate) {
|
|
763
|
-
for (var _b = 0, _c = this.activate; _b < _c.length; _b++) {
|
|
764
|
-
var token = _c[_b];
|
|
765
|
-
context.container.get(token);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
InjectablesProviderController.prototype.unbind = function (context) {
|
|
770
|
-
for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
|
|
771
|
-
var entry = _a[_i];
|
|
772
|
-
var token = core.getEntryToken(entry);
|
|
773
|
-
if (context.container.isBound(token)) {
|
|
774
|
-
context.container.unbind(token);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
if (this.seeds) {
|
|
778
|
-
core.unapplySeeds(context.container, this.seeds);
|
|
779
|
-
}
|
|
780
|
-
this.boundContext = null;
|
|
781
|
-
};
|
|
782
|
-
return InjectablesProviderController;
|
|
783
|
-
}();
|
|
784
|
-
|
|
785
808
|
/**
|
|
786
|
-
* Decorator that
|
|
809
|
+
* Decorator that provides a managed child container derived from the nearest
|
|
810
|
+
* parent container context.
|
|
787
811
|
*
|
|
788
812
|
* @remarks
|
|
789
|
-
*
|
|
813
|
+
* The child container is created from the current parent context when the host
|
|
814
|
+
* connects, destroyed when it disconnects, and recreated when the parent
|
|
815
|
+
* container changes.
|
|
790
816
|
*
|
|
791
817
|
* @group Provision
|
|
792
818
|
*
|
|
793
819
|
* @param options - Provisioning options.
|
|
794
|
-
* @
|
|
820
|
+
* @param options.options - Child-container creation options.
|
|
821
|
+
* @returns An instance of {@link SubContainerProviderDecorator}.
|
|
795
822
|
*
|
|
796
823
|
* @example
|
|
797
824
|
* ```typescript
|
|
798
825
|
* class MyComponent extends LitElement {
|
|
799
|
-
* @
|
|
800
|
-
*
|
|
826
|
+
* @subContainerProvide({
|
|
827
|
+
* options: {
|
|
828
|
+
* entries: [AuthService, UserService],
|
|
829
|
+
* activate: [AuthService],
|
|
830
|
+
* },
|
|
831
|
+
* })
|
|
832
|
+
* public containerProvider!: SubContainerProvider<MyComponent>;
|
|
801
833
|
* }
|
|
802
834
|
* ```
|
|
803
835
|
*/
|
|
804
|
-
function
|
|
805
|
-
return
|
|
836
|
+
function subContainerProvide(options) {
|
|
837
|
+
return (protoOrTarget, nameOrContext) => {
|
|
806
838
|
if (typeof nameOrContext === "object") {
|
|
807
839
|
// Standard decorators:
|
|
808
840
|
nameOrContext.addInitializer(function () {
|
|
809
|
-
protoOrTarget.set.call(this, new
|
|
841
|
+
protoOrTarget.set.call(this, new SubContainerProvider(this, options));
|
|
810
842
|
});
|
|
811
843
|
} else {
|
|
812
|
-
|
|
813
|
-
protoOrTarget.constructor.addInitializer(
|
|
814
|
-
|
|
844
|
+
let provider;
|
|
845
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
846
|
+
provider = new SubContainerProvider(element, options);
|
|
815
847
|
});
|
|
816
848
|
return {
|
|
817
|
-
get
|
|
818
|
-
return
|
|
849
|
+
get() {
|
|
850
|
+
return provider;
|
|
819
851
|
},
|
|
820
|
-
set
|
|
852
|
+
set() {},
|
|
821
853
|
configurable: true,
|
|
822
854
|
enumerable: true
|
|
823
855
|
};
|
|
@@ -826,67 +858,93 @@ function injectablesProvide(options) {
|
|
|
826
858
|
}
|
|
827
859
|
|
|
828
860
|
/**
|
|
829
|
-
* Hook that
|
|
861
|
+
* Hook that provides a container to the host element and its children.
|
|
862
|
+
*
|
|
863
|
+
* @remarks
|
|
864
|
+
* Pass `container` to expose an external `Container` without taking
|
|
865
|
+
* ownership. Pass `options` to create a managed container during
|
|
866
|
+
* construction, activate configured entries on connect, destroy it on
|
|
867
|
+
* disconnect, and recreate it on reconnect.
|
|
830
868
|
*
|
|
831
869
|
* @group Provision
|
|
832
870
|
*
|
|
833
871
|
* @param host - The host element.
|
|
834
872
|
* @param options - Provisioning options.
|
|
835
|
-
* @
|
|
873
|
+
* @param options.container - External container instance to provide.
|
|
874
|
+
* @param options.options - Managed container creation options.
|
|
875
|
+
* @returns An instance of {@link ContainerProvider}.
|
|
836
876
|
*
|
|
837
877
|
* @example
|
|
838
878
|
* ```typescript
|
|
839
|
-
* class
|
|
840
|
-
* private
|
|
841
|
-
*
|
|
842
|
-
*
|
|
879
|
+
* class MyRootElement extends LitElement {
|
|
880
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, {
|
|
881
|
+
* options: {
|
|
882
|
+
* entries: [LoggerService],
|
|
883
|
+
* activate: [LoggerService],
|
|
884
|
+
* },
|
|
843
885
|
* });
|
|
844
886
|
* }
|
|
845
887
|
* ```
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* ```typescript
|
|
891
|
+
* class MyRootElement extends LitElement {
|
|
892
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
|
|
893
|
+
* }
|
|
894
|
+
* ```
|
|
846
895
|
*/
|
|
847
|
-
function
|
|
848
|
-
return new
|
|
896
|
+
function useContainerProvision(host, options) {
|
|
897
|
+
return new ContainerProvider(host, options);
|
|
849
898
|
}
|
|
850
899
|
|
|
851
900
|
/**
|
|
852
|
-
* Hook that provides
|
|
901
|
+
* Hook that provides a managed child container for the host element's lifetime.
|
|
902
|
+
*
|
|
903
|
+
* @remarks
|
|
904
|
+
* The child container is derived from the current parent
|
|
905
|
+
* {@link ContainerContext}, recreated when that parent context changes, and
|
|
906
|
+
* destroyed when the host disconnects.
|
|
853
907
|
*
|
|
854
908
|
* @group Provision
|
|
855
909
|
*
|
|
856
910
|
* @param host - The host element.
|
|
857
911
|
* @param options - Provisioning options.
|
|
858
|
-
* @
|
|
912
|
+
* @param options.options - Child-container creation options.
|
|
913
|
+
* @returns An instance of {@link SubContainerProvider}.
|
|
859
914
|
*
|
|
860
915
|
* @example
|
|
861
916
|
* ```typescript
|
|
862
|
-
* class
|
|
863
|
-
* private
|
|
917
|
+
* class MyComponent extends LitElement {
|
|
918
|
+
* private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
|
|
919
|
+
* options: {
|
|
920
|
+
* entries: [AuthService, UserService],
|
|
921
|
+
* },
|
|
922
|
+
* });
|
|
864
923
|
* }
|
|
865
924
|
* ```
|
|
866
925
|
*/
|
|
867
|
-
function
|
|
868
|
-
|
|
869
|
-
options = {};
|
|
870
|
-
}
|
|
871
|
-
return new IocProviderController(host, options);
|
|
926
|
+
function useSubContainerProvider(host, options) {
|
|
927
|
+
return new SubContainerProvider(host, options);
|
|
872
928
|
}
|
|
873
929
|
|
|
874
|
-
exports.
|
|
875
|
-
exports.
|
|
876
|
-
exports.IocProviderController = IocProviderController;
|
|
930
|
+
exports.ContainerContext = ContainerContext;
|
|
931
|
+
exports.ContainerProvider = ContainerProvider;
|
|
877
932
|
exports.OnCommandController = OnCommandController;
|
|
878
933
|
exports.OnEventController = OnEventController;
|
|
879
934
|
exports.OnQueryController = OnQueryController;
|
|
880
|
-
exports.
|
|
935
|
+
exports.SubContainerProvider = SubContainerProvider;
|
|
936
|
+
exports.containerProvide = containerProvide;
|
|
881
937
|
exports.injection = injection;
|
|
882
|
-
exports.iocProvide = iocProvide;
|
|
883
938
|
exports.onCommand = onCommand;
|
|
884
939
|
exports.onEvent = onEvent;
|
|
885
940
|
exports.onQuery = onQuery;
|
|
886
|
-
exports.
|
|
941
|
+
exports.subContainerProvide = subContainerProvide;
|
|
942
|
+
exports.useContainer = useContainer;
|
|
943
|
+
exports.useContainerProvision = useContainerProvision;
|
|
887
944
|
exports.useInjection = useInjection;
|
|
888
|
-
exports.useIocProvision = useIocProvision;
|
|
889
945
|
exports.useOnCommand = useOnCommand;
|
|
890
946
|
exports.useOnEvents = useOnEvents;
|
|
891
947
|
exports.useOnQuery = useOnQuery;
|
|
948
|
+
exports.useScope = useScope;
|
|
949
|
+
exports.useSubContainerProvider = useSubContainerProvider;
|
|
892
950
|
//# sourceMappingURL=index.js.map
|