@wirestate/lit 0.7.0-experimental.2 → 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/cjs/development/index.js +164 -191
- 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 +17 -20
- 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 +10 -9
- package/esm/development/consumption/injection.js.map +1 -1
- package/esm/development/consumption/use-container.js +2 -2
- package/esm/development/consumption/use-container.js.map +1 -1
- package/esm/development/consumption/use-injection.js +9 -7
- package/esm/development/consumption/use-injection.js.map +1 -1
- package/esm/development/consumption/use-scope.js +2 -2
- package/esm/development/consumption/use-scope.js.map +1 -1
- package/esm/development/context/container-context.js +2 -2
- package/esm/development/context/container-context.js.map +1 -1
- 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 +20 -24
- 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/provision/container-provide.js +7 -7
- package/esm/development/provision/container-provide.js.map +1 -1
- package/esm/development/provision/container-provider.js +17 -23
- package/esm/development/provision/container-provider.js.map +1 -1
- package/esm/development/provision/sub-container-provide.js +7 -7
- package/esm/development/provision/sub-container-provide.js.map +1 -1
- package/esm/development/provision/sub-container-provider.js +28 -31
- package/esm/development/provision/sub-container-provider.js.map +1 -1
- package/esm/development/queries/on-query-controller.js +17 -20
- 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 -1
- package/esm/production/consumption/use-container.js.map +1 -1
- package/esm/production/consumption/use-injection.js +1 -1
- package/esm/production/consumption/use-injection.js.map +1 -1
- package/esm/production/consumption/use-scope.js +1 -1
- package/esm/production/consumption/use-scope.js.map +1 -1
- package/esm/production/context/container-context.js +1 -1
- package/esm/production/context/container-context.js.map +1 -1
- 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/provision/container-provide.js +1 -1
- package/esm/production/provision/container-provide.js.map +1 -1
- package/esm/production/provision/container-provider.js +1 -1
- package/esm/production/provision/container-provider.js.map +1 -1
- package/esm/production/provision/sub-container-provide.js +1 -1
- package/esm/production/provision/sub-container-provide.js.map +1 -1
- package/esm/production/provision/sub-container-provider.js +1 -1
- package/esm/production/provision/sub-container-provider.js.map +1 -1
- package/esm/production/queries/on-query-controller.js +1 -1
- package/esm/production/queries/on-query-controller.js.map +1 -1
- package/esm/production/queries/on-query.js +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/package.json +1 -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
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,30 +49,31 @@ var ContainerContext = context.createContext(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
64
|
context: ContainerContext,
|
|
65
|
-
callback:
|
|
66
|
-
protoOrTarget.set.call(
|
|
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
75
|
context: ContainerContext,
|
|
76
|
-
callback:
|
|
76
|
+
callback: container => {
|
|
77
77
|
element[nameOrContext] = container.get(injectionId);
|
|
78
78
|
},
|
|
79
79
|
subscribe: !once
|
|
@@ -106,12 +106,12 @@ function injection(optionsOrInjectionId) {
|
|
|
106
106
|
* ```
|
|
107
107
|
*/
|
|
108
108
|
function useContainer(host) {
|
|
109
|
-
|
|
109
|
+
const current = {
|
|
110
110
|
value: null
|
|
111
111
|
};
|
|
112
112
|
new context.ContextConsumer(host, {
|
|
113
113
|
context: ContainerContext,
|
|
114
|
-
callback:
|
|
114
|
+
callback: container => {
|
|
115
115
|
current.value = container;
|
|
116
116
|
}
|
|
117
117
|
});
|
|
@@ -150,20 +150,22 @@ function useContainer(host) {
|
|
|
150
150
|
* ```
|
|
151
151
|
*/
|
|
152
152
|
function useInjection(host, optionsOrInjectionId) {
|
|
153
|
-
|
|
153
|
+
const options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
|
|
154
154
|
injectionId: optionsOrInjectionId
|
|
155
155
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
const {
|
|
157
|
+
once,
|
|
158
|
+
injectionId,
|
|
159
|
+
value
|
|
160
|
+
} = options;
|
|
161
|
+
const current = {
|
|
160
162
|
value: value,
|
|
161
|
-
injectionId
|
|
163
|
+
injectionId
|
|
162
164
|
};
|
|
163
165
|
new context.ContextConsumer(host, {
|
|
164
166
|
context: ContainerContext,
|
|
165
167
|
subscribe: !once,
|
|
166
|
-
callback:
|
|
168
|
+
callback: container => {
|
|
167
169
|
current.value = container.get(injectionId);
|
|
168
170
|
}
|
|
169
171
|
});
|
|
@@ -194,14 +196,14 @@ function useInjection(host, optionsOrInjectionId) {
|
|
|
194
196
|
* ```
|
|
195
197
|
*/
|
|
196
198
|
function useScope(host) {
|
|
197
|
-
|
|
199
|
+
const current = {
|
|
198
200
|
value: undefined,
|
|
199
201
|
injectionId: core.WireScope
|
|
200
202
|
};
|
|
201
203
|
new context.ContextConsumer(host, {
|
|
202
204
|
context: ContainerContext,
|
|
203
205
|
subscribe: true,
|
|
204
|
-
callback:
|
|
206
|
+
callback: container => {
|
|
205
207
|
current.value = container.get(core.WireScope);
|
|
206
208
|
}
|
|
207
209
|
});
|
|
@@ -217,49 +219,46 @@ function useScope(host) {
|
|
|
217
219
|
*
|
|
218
220
|
* @group Commands
|
|
219
221
|
*/
|
|
220
|
-
|
|
222
|
+
class OnCommandController {
|
|
223
|
+
bus = null;
|
|
224
|
+
unregister = null;
|
|
221
225
|
/**
|
|
222
226
|
* @param host - The host element.
|
|
223
227
|
* @param type - Unique identifier of the command to handle.
|
|
224
228
|
* @param handler - The command handler function.
|
|
225
229
|
*/
|
|
226
|
-
|
|
227
|
-
var _this = this;
|
|
228
|
-
this.bus = null;
|
|
229
|
-
this.unregister = null;
|
|
230
|
+
constructor(host, type, handler) {
|
|
230
231
|
host.addController(this);
|
|
231
232
|
this.type = type;
|
|
232
233
|
this.handler = handler;
|
|
233
234
|
new context.ContextConsumer(host, {
|
|
234
235
|
context: ContainerContext,
|
|
235
236
|
subscribe: true,
|
|
236
|
-
callback:
|
|
237
|
-
|
|
237
|
+
callback: container => {
|
|
238
|
+
this.bus = container.get(core.CommandBus);
|
|
238
239
|
if (host.isConnected) {
|
|
239
|
-
|
|
240
|
+
this.reregister();
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
});
|
|
243
244
|
}
|
|
244
|
-
|
|
245
|
+
hostConnected() {
|
|
245
246
|
this.reregister();
|
|
246
|
-
}
|
|
247
|
-
|
|
247
|
+
}
|
|
248
|
+
hostDisconnected() {
|
|
248
249
|
this.cleanup();
|
|
249
|
-
}
|
|
250
|
-
|
|
250
|
+
}
|
|
251
|
+
reregister() {
|
|
251
252
|
this.cleanup();
|
|
252
253
|
if (this.bus) {
|
|
253
254
|
this.unregister = this.bus.register(this.type, this.handler);
|
|
254
255
|
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
(_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
256
|
+
}
|
|
257
|
+
cleanup() {
|
|
258
|
+
this.unregister?.();
|
|
259
259
|
this.unregister = null;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
}();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
263
262
|
|
|
264
263
|
/**
|
|
265
264
|
* Decorator for Lit element methods that handle a specific command.
|
|
@@ -283,21 +282,16 @@ var OnCommandController = /** @class */function () {
|
|
|
283
282
|
* ```
|
|
284
283
|
*/
|
|
285
284
|
function onCommand(type) {
|
|
286
|
-
return
|
|
285
|
+
return (protoOrTarget, nameOrContext) => {
|
|
287
286
|
if (typeof nameOrContext === "object") {
|
|
288
287
|
// Standard decorators:
|
|
289
288
|
nameOrContext.addInitializer(function () {
|
|
290
|
-
|
|
291
|
-
new OnCommandController(this, type, function (data) {
|
|
292
|
-
return _this[nameOrContext.name](data);
|
|
293
|
-
});
|
|
289
|
+
new OnCommandController(this, type, data => this[nameOrContext.name](data));
|
|
294
290
|
});
|
|
295
291
|
} else {
|
|
296
292
|
// Experimental legacy decorators:
|
|
297
|
-
protoOrTarget.constructor.addInitializer(
|
|
298
|
-
new OnCommandController(element, type,
|
|
299
|
-
return element[nameOrContext](data);
|
|
300
|
-
});
|
|
293
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
294
|
+
new OnCommandController(element, type, data => element[nameOrContext](data));
|
|
301
295
|
});
|
|
302
296
|
}
|
|
303
297
|
};
|
|
@@ -324,9 +318,10 @@ function onCommand(type) {
|
|
|
324
318
|
* }
|
|
325
319
|
* ```
|
|
326
320
|
*/
|
|
327
|
-
function useOnCommand(host,
|
|
328
|
-
|
|
329
|
-
|
|
321
|
+
function useOnCommand(host, {
|
|
322
|
+
type,
|
|
323
|
+
handler
|
|
324
|
+
}) {
|
|
330
325
|
return new OnCommandController(host, type, handler);
|
|
331
326
|
}
|
|
332
327
|
|
|
@@ -339,58 +334,54 @@ function useOnCommand(host, _a) {
|
|
|
339
334
|
*
|
|
340
335
|
* @group Events
|
|
341
336
|
*/
|
|
342
|
-
|
|
337
|
+
class OnEventController {
|
|
338
|
+
bus = null;
|
|
339
|
+
unsubscriber = null;
|
|
343
340
|
/**
|
|
344
341
|
* @param host - The host element.
|
|
345
342
|
* @param types - Event types to listen for. If null, all events will be handled.
|
|
346
343
|
* @param handler - The event handler function.
|
|
347
344
|
*/
|
|
348
|
-
|
|
349
|
-
var _this = this;
|
|
350
|
-
this.bus = null;
|
|
351
|
-
this.unsubscriber = null;
|
|
345
|
+
constructor(host, types, handler) {
|
|
352
346
|
host.addController(this);
|
|
353
347
|
this.types = types;
|
|
354
348
|
this.handler = handler;
|
|
355
349
|
new context.ContextConsumer(host, {
|
|
356
350
|
context: ContainerContext,
|
|
357
351
|
subscribe: true,
|
|
358
|
-
callback:
|
|
359
|
-
|
|
352
|
+
callback: container => {
|
|
353
|
+
this.bus = container.get(core.EventBus);
|
|
360
354
|
if (host.isConnected) {
|
|
361
|
-
|
|
355
|
+
this.resubscribe();
|
|
362
356
|
}
|
|
363
357
|
}
|
|
364
358
|
});
|
|
365
359
|
}
|
|
366
|
-
|
|
360
|
+
hostConnected() {
|
|
367
361
|
this.resubscribe();
|
|
368
|
-
}
|
|
369
|
-
|
|
362
|
+
}
|
|
363
|
+
hostDisconnected() {
|
|
370
364
|
this.cleanup();
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
var _this = this;
|
|
365
|
+
}
|
|
366
|
+
resubscribe() {
|
|
374
367
|
this.cleanup();
|
|
375
368
|
if (this.bus) {
|
|
376
369
|
if (this.types === null) {
|
|
377
370
|
this.unsubscriber = this.bus.subscribe(this.handler);
|
|
378
371
|
} else {
|
|
379
|
-
this.unsubscriber = this.bus.subscribe(
|
|
380
|
-
if (
|
|
381
|
-
|
|
372
|
+
this.unsubscriber = this.bus.subscribe(event => {
|
|
373
|
+
if (this.types.includes(event.type)) {
|
|
374
|
+
this.handler(event);
|
|
382
375
|
}
|
|
383
376
|
});
|
|
384
377
|
}
|
|
385
378
|
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
(_a = this.unsubscriber) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
379
|
+
}
|
|
380
|
+
cleanup() {
|
|
381
|
+
this.unsubscriber?.();
|
|
390
382
|
this.unsubscriber = null;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
}();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
394
385
|
|
|
395
386
|
/**
|
|
396
387
|
* Decorator for Lit element methods that handle events from the event bus.
|
|
@@ -434,22 +425,17 @@ var OnEventController = /** @class */function () {
|
|
|
434
425
|
* ```
|
|
435
426
|
*/
|
|
436
427
|
function onEvent(types) {
|
|
437
|
-
|
|
438
|
-
return
|
|
428
|
+
const normalized = types === undefined ? null : Array.isArray(types) ? [...types] : [types];
|
|
429
|
+
return (protoOrTarget, nameOrContext) => {
|
|
439
430
|
if (typeof nameOrContext === "object") {
|
|
440
431
|
// Standard decorators:
|
|
441
432
|
nameOrContext.addInitializer(function () {
|
|
442
|
-
|
|
443
|
-
new OnEventController(this, normalized, function (event) {
|
|
444
|
-
return _this[nameOrContext.name](event);
|
|
445
|
-
});
|
|
433
|
+
new OnEventController(this, normalized, event => this[nameOrContext.name](event));
|
|
446
434
|
});
|
|
447
435
|
} else {
|
|
448
436
|
// Experimental legacy decorators:
|
|
449
|
-
protoOrTarget.constructor.addInitializer(
|
|
450
|
-
new OnEventController(element, normalized,
|
|
451
|
-
return element[nameOrContext](event);
|
|
452
|
-
});
|
|
437
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
438
|
+
new OnEventController(element, normalized, event => element[nameOrContext](event));
|
|
453
439
|
});
|
|
454
440
|
}
|
|
455
441
|
};
|
|
@@ -485,10 +471,11 @@ function onEvent(types) {
|
|
|
485
471
|
* }
|
|
486
472
|
* ```
|
|
487
473
|
*/
|
|
488
|
-
function useOnEvents(host,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
474
|
+
function useOnEvents(host, {
|
|
475
|
+
types,
|
|
476
|
+
handler
|
|
477
|
+
}) {
|
|
478
|
+
const normalized = types ? Array.isArray(types) ? [...types] : [types] : null;
|
|
492
479
|
return new OnEventController(host, normalized, handler);
|
|
493
480
|
}
|
|
494
481
|
|
|
@@ -501,49 +488,46 @@ function useOnEvents(host, _a) {
|
|
|
501
488
|
*
|
|
502
489
|
* @group Queries
|
|
503
490
|
*/
|
|
504
|
-
|
|
491
|
+
class OnQueryController {
|
|
492
|
+
bus = null;
|
|
493
|
+
unregister = null;
|
|
505
494
|
/**
|
|
506
495
|
* @param host - The host element.
|
|
507
496
|
* @param type - Unique identifier of the query to handle.
|
|
508
497
|
* @param handler - The query handler function.
|
|
509
498
|
*/
|
|
510
|
-
|
|
511
|
-
var _this = this;
|
|
512
|
-
this.bus = null;
|
|
513
|
-
this.unregister = null;
|
|
499
|
+
constructor(host, type, handler) {
|
|
514
500
|
host.addController(this);
|
|
515
501
|
this.type = type;
|
|
516
502
|
this.handler = handler;
|
|
517
503
|
new context.ContextConsumer(host, {
|
|
518
504
|
context: ContainerContext,
|
|
519
505
|
subscribe: true,
|
|
520
|
-
callback:
|
|
521
|
-
|
|
506
|
+
callback: container => {
|
|
507
|
+
this.bus = container.get(core.QueryBus);
|
|
522
508
|
if (host.isConnected) {
|
|
523
|
-
|
|
509
|
+
this.reregister();
|
|
524
510
|
}
|
|
525
511
|
}
|
|
526
512
|
});
|
|
527
513
|
}
|
|
528
|
-
|
|
514
|
+
hostConnected() {
|
|
529
515
|
this.reregister();
|
|
530
|
-
}
|
|
531
|
-
|
|
516
|
+
}
|
|
517
|
+
hostDisconnected() {
|
|
532
518
|
this.cleanup();
|
|
533
|
-
}
|
|
534
|
-
|
|
519
|
+
}
|
|
520
|
+
reregister() {
|
|
535
521
|
this.cleanup();
|
|
536
522
|
if (this.bus) {
|
|
537
523
|
this.unregister = this.bus.register(this.type, this.handler);
|
|
538
524
|
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
(_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
525
|
+
}
|
|
526
|
+
cleanup() {
|
|
527
|
+
this.unregister?.();
|
|
543
528
|
this.unregister = null;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
}();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
547
531
|
|
|
548
532
|
/**
|
|
549
533
|
* Decorator for Lit element methods that handle a specific query.
|
|
@@ -567,21 +551,16 @@ var OnQueryController = /** @class */function () {
|
|
|
567
551
|
* ```
|
|
568
552
|
*/
|
|
569
553
|
function onQuery(type) {
|
|
570
|
-
return
|
|
554
|
+
return (protoOrTarget, nameOrContext) => {
|
|
571
555
|
if (typeof nameOrContext === "object") {
|
|
572
556
|
// Standard decorators:
|
|
573
557
|
nameOrContext.addInitializer(function () {
|
|
574
|
-
|
|
575
|
-
new OnQueryController(this, type, function (data) {
|
|
576
|
-
return _this[nameOrContext.name](data);
|
|
577
|
-
});
|
|
558
|
+
new OnQueryController(this, type, data => this[nameOrContext.name](data));
|
|
578
559
|
});
|
|
579
560
|
} else {
|
|
580
561
|
// Experimental legacy decorators:
|
|
581
|
-
protoOrTarget.constructor.addInitializer(
|
|
582
|
-
new OnQueryController(element, type,
|
|
583
|
-
return element[nameOrContext](data);
|
|
584
|
-
});
|
|
562
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
563
|
+
new OnQueryController(element, type, data => element[nameOrContext](data));
|
|
585
564
|
});
|
|
586
565
|
}
|
|
587
566
|
};
|
|
@@ -608,13 +587,14 @@ function onQuery(type) {
|
|
|
608
587
|
* }
|
|
609
588
|
* ```
|
|
610
589
|
*/
|
|
611
|
-
function useOnQuery(host,
|
|
612
|
-
|
|
613
|
-
|
|
590
|
+
function useOnQuery(host, {
|
|
591
|
+
type,
|
|
592
|
+
handler
|
|
593
|
+
}) {
|
|
614
594
|
return new OnQueryController(host, type, handler);
|
|
615
595
|
}
|
|
616
596
|
|
|
617
|
-
|
|
597
|
+
const ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
618
598
|
|
|
619
599
|
/**
|
|
620
600
|
* Provider that exposes an IoC container context to the host element and its children.
|
|
@@ -631,56 +611,51 @@ var ERROR_CODE_INVALID_ARGUMENTS = 2051;
|
|
|
631
611
|
*
|
|
632
612
|
* @group Provision
|
|
633
613
|
*/
|
|
634
|
-
|
|
635
|
-
|
|
614
|
+
class ContainerProvider extends context.ContextProvider {
|
|
615
|
+
destroyed = false;
|
|
636
616
|
/**
|
|
637
617
|
* @param host - The host element.
|
|
638
618
|
* @param options - Provisioning options.
|
|
639
619
|
* @param options.container - External container instance to provide.
|
|
640
620
|
* @param options.options - Managed container creation options.
|
|
641
621
|
*/
|
|
642
|
-
|
|
643
|
-
var _this = this;
|
|
622
|
+
constructor(host, options) {
|
|
644
623
|
if (!options.container && !options.options) {
|
|
645
624
|
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
|
|
646
625
|
} else if (options.container && options.options) {
|
|
647
626
|
throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
|
|
648
627
|
}
|
|
649
|
-
|
|
628
|
+
super(host, {
|
|
650
629
|
context: ContainerContext,
|
|
651
|
-
initialValue: options.container ? options.container : core.createContainer(
|
|
630
|
+
initialValue: options.container ? options.container : core.createContainer({
|
|
631
|
+
...options.options,
|
|
652
632
|
activate: []
|
|
653
|
-
})
|
|
654
|
-
})
|
|
655
|
-
|
|
656
|
-
_this.options = options.options;
|
|
657
|
-
return _this;
|
|
633
|
+
})
|
|
634
|
+
});
|
|
635
|
+
this.options = options.options;
|
|
658
636
|
}
|
|
659
|
-
|
|
660
|
-
var _a;
|
|
637
|
+
hostConnected() {
|
|
661
638
|
if (this.options) {
|
|
662
639
|
if (this.destroyed) {
|
|
663
640
|
this.value = core.createContainer(this.options);
|
|
664
641
|
this.destroyed = false;
|
|
665
642
|
} else {
|
|
666
|
-
if (
|
|
667
|
-
for (
|
|
668
|
-
var entry = _b[_i];
|
|
643
|
+
if (this.options?.activate) {
|
|
644
|
+
for (const entry of this.options.activate) {
|
|
669
645
|
this.value.get(entry);
|
|
670
646
|
}
|
|
671
647
|
}
|
|
672
648
|
}
|
|
673
649
|
}
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
|
|
650
|
+
super.hostConnected();
|
|
651
|
+
}
|
|
652
|
+
hostDisconnected() {
|
|
677
653
|
if (this.options) {
|
|
678
654
|
this.value.unbindAll();
|
|
679
655
|
this.destroyed = true;
|
|
680
656
|
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
}(context.ContextProvider);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
684
659
|
|
|
685
660
|
/**
|
|
686
661
|
* Provider that exposes a managed child container for the host element's lifetime.
|
|
@@ -706,67 +681,65 @@ var ContainerProvider = /** @class */function (_super) {
|
|
|
706
681
|
* }
|
|
707
682
|
* ```
|
|
708
683
|
*/
|
|
709
|
-
|
|
710
|
-
|
|
684
|
+
class SubContainerProvider extends context.ContextProvider {
|
|
685
|
+
parent = null;
|
|
686
|
+
destroyed = true;
|
|
711
687
|
/**
|
|
712
688
|
* @param host - The host element.
|
|
713
689
|
* @param options - Provisioning options, including child entries, eager activations, and seeds.
|
|
714
690
|
*/
|
|
715
|
-
|
|
716
|
-
|
|
691
|
+
constructor(host, options) {
|
|
692
|
+
super(host, {
|
|
717
693
|
context: ContainerContext
|
|
718
|
-
})
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
_this.options = options.options;
|
|
722
|
-
_this.consumer = new context.ContextConsumer(host, {
|
|
694
|
+
});
|
|
695
|
+
this.options = options.options;
|
|
696
|
+
this.consumer = new context.ContextConsumer(host, {
|
|
723
697
|
context: ContainerContext,
|
|
724
698
|
subscribe: true,
|
|
725
|
-
callback:
|
|
726
|
-
|
|
727
|
-
|
|
699
|
+
callback: context => {
|
|
700
|
+
const previousParent = this.parent;
|
|
701
|
+
this.parent = context;
|
|
728
702
|
if (host.isConnected) {
|
|
729
|
-
if (
|
|
730
|
-
|
|
731
|
-
|
|
703
|
+
if (this.destroyed || !this.value || previousParent !== context) {
|
|
704
|
+
this.destroyContainer();
|
|
705
|
+
this.createContainer();
|
|
732
706
|
}
|
|
733
707
|
}
|
|
734
708
|
}
|
|
735
709
|
});
|
|
736
|
-
return _this;
|
|
737
710
|
}
|
|
738
|
-
|
|
711
|
+
hostConnected() {
|
|
739
712
|
if (this.parent && (this.destroyed || !this.value)) {
|
|
740
713
|
this.destroyContainer();
|
|
741
714
|
this.createContainer();
|
|
742
715
|
}
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
|
|
716
|
+
super.hostConnected();
|
|
717
|
+
}
|
|
718
|
+
hostDisconnected() {
|
|
746
719
|
this.destroyContainer();
|
|
747
|
-
}
|
|
720
|
+
}
|
|
748
721
|
/**
|
|
749
722
|
* Replaces the currently provided child container with a new one derived
|
|
750
723
|
* from the latest parent context.
|
|
751
724
|
*/
|
|
752
|
-
|
|
753
|
-
|
|
725
|
+
createContainer() {
|
|
726
|
+
const container = core.createContainer({
|
|
727
|
+
...this.options,
|
|
754
728
|
parent: this.parent
|
|
755
|
-
})
|
|
729
|
+
});
|
|
756
730
|
this.destroyed = false;
|
|
757
731
|
this.value = container;
|
|
758
|
-
}
|
|
732
|
+
}
|
|
759
733
|
/**
|
|
760
734
|
* Destroys the currently provided child container.
|
|
761
735
|
*/
|
|
762
|
-
|
|
736
|
+
destroyContainer() {
|
|
763
737
|
if (this.value && !this.destroyed) {
|
|
764
738
|
this.value.unbindAll();
|
|
765
739
|
this.destroyed = true;
|
|
766
740
|
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
}(context.ContextProvider);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
770
743
|
|
|
771
744
|
/**
|
|
772
745
|
* Decorator that provides an IoC container to child components.
|
|
@@ -809,22 +782,22 @@ var SubContainerProvider = /** @class */function (_super) {
|
|
|
809
782
|
* ```
|
|
810
783
|
*/
|
|
811
784
|
function containerProvide(options) {
|
|
812
|
-
return
|
|
785
|
+
return (protoOrTarget, nameOrContext) => {
|
|
813
786
|
if (typeof nameOrContext === "object") {
|
|
814
787
|
// Standard decorators:
|
|
815
788
|
nameOrContext.addInitializer(function () {
|
|
816
789
|
protoOrTarget.set.call(this, new ContainerProvider(this, options));
|
|
817
790
|
});
|
|
818
791
|
} else {
|
|
819
|
-
|
|
820
|
-
protoOrTarget.constructor.addInitializer(
|
|
821
|
-
|
|
792
|
+
let controller;
|
|
793
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
794
|
+
controller = new ContainerProvider(element, options);
|
|
822
795
|
});
|
|
823
796
|
return {
|
|
824
|
-
get
|
|
825
|
-
return
|
|
797
|
+
get() {
|
|
798
|
+
return controller;
|
|
826
799
|
},
|
|
827
|
-
set
|
|
800
|
+
set() {},
|
|
828
801
|
configurable: true,
|
|
829
802
|
enumerable: true
|
|
830
803
|
};
|
|
@@ -861,22 +834,22 @@ function containerProvide(options) {
|
|
|
861
834
|
* ```
|
|
862
835
|
*/
|
|
863
836
|
function subContainerProvide(options) {
|
|
864
|
-
return
|
|
837
|
+
return (protoOrTarget, nameOrContext) => {
|
|
865
838
|
if (typeof nameOrContext === "object") {
|
|
866
839
|
// Standard decorators:
|
|
867
840
|
nameOrContext.addInitializer(function () {
|
|
868
841
|
protoOrTarget.set.call(this, new SubContainerProvider(this, options));
|
|
869
842
|
});
|
|
870
843
|
} else {
|
|
871
|
-
|
|
872
|
-
protoOrTarget.constructor.addInitializer(
|
|
873
|
-
|
|
844
|
+
let provider;
|
|
845
|
+
protoOrTarget.constructor.addInitializer(element => {
|
|
846
|
+
provider = new SubContainerProvider(element, options);
|
|
874
847
|
});
|
|
875
848
|
return {
|
|
876
|
-
get
|
|
877
|
-
return
|
|
849
|
+
get() {
|
|
850
|
+
return provider;
|
|
878
851
|
},
|
|
879
|
-
set
|
|
852
|
+
set() {},
|
|
880
853
|
configurable: true,
|
|
881
854
|
enumerable: true
|
|
882
855
|
};
|