@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
|
@@ -2,19 +2,22 @@ import { __spreadArray } from 'tslib';
|
|
|
2
2
|
import { OnEventController } from './on-event-controller.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Decorator
|
|
5
|
+
* Decorator for Lit element methods that handle events from the event bus.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @remarks
|
|
8
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
9
|
+
*
|
|
10
|
+
* @group Events
|
|
8
11
|
*
|
|
9
12
|
* @param types - Event types to listen for. If omitted, all events will be handled.
|
|
10
|
-
* @returns
|
|
13
|
+
* @returns A method decorator function.
|
|
11
14
|
*
|
|
12
15
|
* @example
|
|
13
16
|
* ```typescript
|
|
14
17
|
* class MyElement extends LitElement {
|
|
15
18
|
* @onEvent()
|
|
16
19
|
* private onMyEvent(event: Event) {
|
|
17
|
-
* console.log(
|
|
20
|
+
* console.log("Event received:", event);
|
|
18
21
|
* }
|
|
19
22
|
* }
|
|
20
23
|
* ```
|
|
@@ -22,9 +25,9 @@ import { OnEventController } from './on-event-controller.js';
|
|
|
22
25
|
* @example
|
|
23
26
|
* ```typescript
|
|
24
27
|
* class MyElement extends LitElement {
|
|
25
|
-
* @onEvent(
|
|
28
|
+
* @onEvent("MY_EVENT_TYPE")
|
|
26
29
|
* private onMyEvent(event: MyEvent) {
|
|
27
|
-
* console.log(
|
|
30
|
+
* console.log("Event received:", event);
|
|
28
31
|
* }
|
|
29
32
|
* }
|
|
30
33
|
* ```
|
|
@@ -32,9 +35,9 @@ import { OnEventController } from './on-event-controller.js';
|
|
|
32
35
|
* @example
|
|
33
36
|
* ```typescript
|
|
34
37
|
* class MyElement extends LitElement {
|
|
35
|
-
* @onEvent([
|
|
38
|
+
* @onEvent(["MY_EVENT_TYPE_1", "MY_EVENT_TYPE_2"])
|
|
36
39
|
* private onMyEvent(event: Event) {
|
|
37
|
-
* console.log(
|
|
40
|
+
* console.log("Event received:", event);
|
|
38
41
|
* }
|
|
39
42
|
* }
|
|
40
43
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-event.js","sources":["../../../../../../../../src/wirestate-lit/events/on-event.ts"],"sourcesContent":[null],"names":["onEvent","types","normalized","undefined","Array","isArray","__spreadArray","protoOrTarget","nameOrContext","addInitializer","_this","OnEventController","event","name","constructor","element"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"on-event.js","sources":["../../../../../../../../src/wirestate-lit/events/on-event.ts"],"sourcesContent":[null],"names":["onEvent","types","normalized","undefined","Array","isArray","__spreadArray","protoOrTarget","nameOrContext","addInitializer","_this","OnEventController","event","name","constructor","element"],"mappings":";;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AACG,SAAUA,OAAOA,CAA0BC,KAA4C,EAAA;EAC3F,IAAMC,UAAU,GACdD,KAAK,KAAKE,SAAS,GAAG,IAAI,GAAGC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,GAAEK,aAAA,CAAA,EAAA,EAAML,KAAkC,EAAA,IAAA,CAAA,GAAI,CAACA,KAAkB,CAAC;AAErH,EAAA,OAAQ,UAACM,aAAqB,EAAEC,aAAwD,EAAA;AACtF,IAAA,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAE;AACrC;MACAA,aAAa,CAACC,cAAc,CAAC,YAAA;QAAA,IAAAC,KAAA,GAAA,IAAA;QAC3B,IAAIC,iBAAiB,CAAC,IAAuB,EAAET,UAAU,EAAE,UAACU,KAAK,EAAA;UAC/D,OAACF,KAAkB,CAACF,aAAa,CAACK,IAAI,CAAC,CAACD,KAAK,CAAC;AAA9C,QAAA,CAA8C,CAC/C;AACH,MAAA,CAAC,CAAC;AACJ,IAAA,CAAC,MAAM;AACL;AACCL,MAAAA,aAAa,CAACO,WAAsC,CAACL,cAAc,CAAC,UAACM,OAAwB,EAAA;QAC5F,IAAIJ,iBAAiB,CAACI,OAAO,EAAEb,UAAU,EAAE,UAACU,KAAK,EAAA;AAAK,UAAA,OAACG,OAAqB,CAACP,aAAa,CAAC,CAACI,KAAK,CAAC;AAA5C,QAAA,CAA4C,CAAC;AACrG,MAAA,CAAC,CAAC;AACJ,IAAA;EACF,CAAC;AACH;;;;"}
|
|
@@ -2,15 +2,15 @@ import { __spreadArray } from 'tslib';
|
|
|
2
2
|
import { OnEventController } from './on-event-controller.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Hook
|
|
5
|
+
* Hook that subscribes to events for the host element's lifetime.
|
|
6
6
|
*
|
|
7
|
-
* @group
|
|
7
|
+
* @group Events
|
|
8
8
|
*
|
|
9
|
-
* @param host -
|
|
10
|
-
* @param options -
|
|
11
|
-
* @param options.handler -
|
|
12
|
-
* @param options.types -
|
|
13
|
-
* @returns
|
|
9
|
+
* @param host - The host element.
|
|
10
|
+
* @param options - Event handling options.
|
|
11
|
+
* @param options.handler - Event handler function.
|
|
12
|
+
* @param options.types - Event types to listen for, if null or undefined, all events will be handled.
|
|
13
|
+
* @returns An instance of {@link OnEventController}.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
@@ -25,7 +25,7 @@ import { OnEventController } from './on-event-controller.js';
|
|
|
25
25
|
* ```typescript
|
|
26
26
|
* class MyElement extends LitElement {
|
|
27
27
|
* private eventHandler = useOnEvents(this, {
|
|
28
|
-
* types: [
|
|
28
|
+
* types: ["MY_EVENT"],
|
|
29
29
|
* handler: (event) => console.log(event),
|
|
30
30
|
* });
|
|
31
31
|
* }
|
package/esm/development/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { injection } from './consumption/injection.js';
|
|
2
|
+
export { useContainer } from './consumption/use-container.js';
|
|
2
3
|
export { useInjection } from './consumption/use-injection.js';
|
|
4
|
+
export { useScope } from './consumption/use-scope.js';
|
|
3
5
|
export { onCommand } from './commands/on-command.js';
|
|
4
6
|
export { OnCommandController } from './commands/on-command-controller.js';
|
|
5
7
|
export { useOnCommand } from './commands/use-on-command.js';
|
|
@@ -9,11 +11,11 @@ export { useOnEvents } from './events/use-on-events.js';
|
|
|
9
11
|
export { onQuery } from './queries/on-query.js';
|
|
10
12
|
export { OnQueryController } from './queries/on-query-controller.js';
|
|
11
13
|
export { useOnQuery } from './queries/use-on-query.js';
|
|
12
|
-
export { ContainerContext } from './context/
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
14
|
+
export { ContainerContext } from './context/container-context.js';
|
|
15
|
+
export { ContainerProvider } from './provision/container-provider.js';
|
|
16
|
+
export { SubContainerProvider } from './provision/sub-container-provider.js';
|
|
17
|
+
export { containerProvide } from './provision/container-provide.js';
|
|
18
|
+
export { subContainerProvide } from './provision/sub-container-provide.js';
|
|
19
|
+
export { useContainerProvision } from './provision/use-container-provision.js';
|
|
20
|
+
export { useSubContainerProvider } from './provision/use-sub-container-provider.js';
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ContainerProvider } from './container-provider.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that provides an IoC container to child components.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The container is provided via Lit context.
|
|
8
|
+
*
|
|
9
|
+
* - Pass `container` to expose an external container without taking
|
|
10
|
+
* ownership.
|
|
11
|
+
* - Pass `options` to create a managed container during construction,
|
|
12
|
+
* activate configured entries on connect, destroy it on disconnect, and
|
|
13
|
+
* recreate it on reconnect.
|
|
14
|
+
*
|
|
15
|
+
* @group Provision
|
|
16
|
+
*
|
|
17
|
+
* @param options - Provisioning options.
|
|
18
|
+
* @param options.container - External container instance to provide.
|
|
19
|
+
* @param options.options - Managed container creation options.
|
|
20
|
+
* @returns An instance of {@link ContainerProviderDecorator}.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* class MyRootElement extends LitElement {
|
|
25
|
+
* @containerProvide({
|
|
26
|
+
* options: {
|
|
27
|
+
* seed: { someData: "value" },
|
|
28
|
+
* entries: [LoggerService],
|
|
29
|
+
* },
|
|
30
|
+
* })
|
|
31
|
+
* private containerProvider!: ContainerProvider;
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* class MyRootElement extends LitElement {
|
|
38
|
+
* @containerProvide({ container: container })
|
|
39
|
+
* private containerProvider!: ContainerProvider;
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function containerProvide(options) {
|
|
44
|
+
return function (protoOrTarget, nameOrContext) {
|
|
45
|
+
if (typeof nameOrContext === "object") {
|
|
46
|
+
// Standard decorators:
|
|
47
|
+
nameOrContext.addInitializer(function () {
|
|
48
|
+
protoOrTarget.set.call(this, new ContainerProvider(this, options));
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
var controller_1;
|
|
52
|
+
protoOrTarget.constructor.addInitializer(function (element) {
|
|
53
|
+
controller_1 = new ContainerProvider(element, options);
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
get: function () {
|
|
57
|
+
return controller_1;
|
|
58
|
+
},
|
|
59
|
+
set: function () {},
|
|
60
|
+
configurable: true,
|
|
61
|
+
enumerable: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { containerProvide };
|
|
68
|
+
//# sourceMappingURL=container-provide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-provide.js","sources":["../../../../../../../../src/wirestate-lit/provision/container-provide.ts"],"sourcesContent":[null],"names":["containerProvide","options","protoOrTarget","nameOrContext","addInitializer","set","call","ContainerProvider","controller_1","constructor","element","get","configurable","enumerable"],"mappings":";;AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AACG,SAAUA,gBAAgBA,CAC9BC,OAAiC,EAAA;AAEjC,EAAA,OAAQ,UACNC,aAAkF,EAClFC,aAAiG,EAAA;AAEjG,IAAA,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAE;AACrC;MACAA,aAAa,CAACC,cAAc,CAAC,YAAA;AAC3BF,QAAAA,aAAa,CAACG,GAAG,CAACC,IAAI,CAAC,IAAI,EAAE,IAAIC,iBAAiB,CAAC,IAAoB,EAAEN,OAAO,CAAC,CAAC;AACpF,MAAA,CAAC,CAAC;AACJ,IAAA,CAAC,MAAM;AACL,MAAA,IAAIO,YAAuC;AAE1CN,MAAAA,aAAa,CAACO,WAAsC,CAACL,cAAc,CAAC,UAACM,OAAwB,EAAA;AAC5FF,QAAAA,YAAU,GAAG,IAAID,iBAAiB,CAACG,OAAY,EAAET,OAAO,CAAC;AAC3D,MAAA,CAAC,CAAC;MAEF,OAAO;QACLU,GAAG,EAAA,YAAA;AACD,UAAA,OAAOH,YAAkC;QAC3C,CAAC;AACDH,QAAAA,GAAG,eAAU,CAAC;AACdO,QAAAA,YAAY,EAAE,IAAI;AAClBC,QAAAA,UAAU,EAAE;OACb;AACH,IAAA;EACF,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { __extends, __assign } from 'tslib';
|
|
2
|
+
import { ContextProvider } from '@lit/context';
|
|
3
|
+
import { WirestateError, createContainer } from '@wirestate/core';
|
|
4
|
+
import { ContainerContext } from '../context/container-context.js';
|
|
5
|
+
import { ERROR_CODE_INVALID_ARGUMENTS } from '../error/error-code.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Provider that exposes an IoC container context to the host element and its children.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The provider supports two modes:
|
|
12
|
+
*
|
|
13
|
+
* - External mode: `container` is an existing {@link Container}. The
|
|
14
|
+
* provider passes it through context and does not alter its lifecycle.
|
|
15
|
+
* - Managed mode: `options` is {@link CreateContainerOptions}. The provider
|
|
16
|
+
* creates a container during construction without eager activation,
|
|
17
|
+
* activates configured entries when the host connects, disposes the
|
|
18
|
+
* container when the host disconnects, and recreates it on reconnect.
|
|
19
|
+
*
|
|
20
|
+
* @group Provision
|
|
21
|
+
*/
|
|
22
|
+
var ContainerProvider = /** @class */function (_super) {
|
|
23
|
+
__extends(ContainerProvider, _super);
|
|
24
|
+
/**
|
|
25
|
+
* @param host - The host element.
|
|
26
|
+
* @param options - Provisioning options.
|
|
27
|
+
* @param options.container - External container instance to provide.
|
|
28
|
+
* @param options.options - Managed container creation options.
|
|
29
|
+
*/
|
|
30
|
+
function ContainerProvider(host, options) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
if (!options.container && !options.options) {
|
|
33
|
+
throw new WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
|
|
34
|
+
} else if (options.container && options.options) {
|
|
35
|
+
throw new WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
|
|
36
|
+
}
|
|
37
|
+
_this = _super.call(this, host, {
|
|
38
|
+
context: ContainerContext,
|
|
39
|
+
initialValue: options.container ? options.container : createContainer(__assign(__assign({}, options.options), {
|
|
40
|
+
activate: []
|
|
41
|
+
}))
|
|
42
|
+
}) || this;
|
|
43
|
+
_this.destroyed = false;
|
|
44
|
+
_this.options = options.options;
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
ContainerProvider.prototype.hostConnected = function () {
|
|
48
|
+
var _a;
|
|
49
|
+
if (this.options) {
|
|
50
|
+
if (this.destroyed) {
|
|
51
|
+
this.value = createContainer(this.options);
|
|
52
|
+
this.destroyed = false;
|
|
53
|
+
} else {
|
|
54
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.activate) {
|
|
55
|
+
for (var _i = 0, _b = this.options.activate; _i < _b.length; _i++) {
|
|
56
|
+
var entry = _b[_i];
|
|
57
|
+
this.value.get(entry);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_super.prototype.hostConnected.call(this);
|
|
63
|
+
};
|
|
64
|
+
ContainerProvider.prototype.hostDisconnected = function () {
|
|
65
|
+
if (this.options) {
|
|
66
|
+
this.value.unbindAll();
|
|
67
|
+
this.destroyed = true;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return ContainerProvider;
|
|
71
|
+
}(ContextProvider);
|
|
72
|
+
|
|
73
|
+
export { ContainerProvider };
|
|
74
|
+
//# sourceMappingURL=container-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-provider.js","sources":["../../../../../../../../src/wirestate-lit/provision/container-provider.ts"],"sourcesContent":[null],"names":["ContainerProvider","_super","__extends","host","options","_this","container","WirestateError","ERROR_CODE_INVALID_ARGUMENTS","call","context","ContainerContext","initialValue","createContainer","activate","destroyed","prototype","hostConnected","value","_a","_i","_b","length","entry","get","hostDisconnected","unbindAll","ContextProvider"],"mappings":";;;;;;AAyCA;;;;;;;;;;;;;;AAcG;AACH,IAAAA,iBAAA,gBAAA,UAAAC,MAAA,EAAA;AACUC,EAAAA,SAAA,CAAAF,iBAAA,EAAAC,MAAA,CAAA;AAOR;;;;;AAKG;AACH,EAAA,SAAAD,iBAAAA,CAAmBG,IAAO,EAAEC,OAAiC,EAAA;IAA7D,IAAAC,KAAA,GAAA,IAAA;IACE,IAAI,CAACD,OAAO,CAACE,SAAS,IAAI,CAACF,OAAO,CAACA,OAAO,EAAE;AAC1C,MAAA,MAAM,IAAIG,cAAc,CACtBC,4BAA4B,EAC5B,4EAA4E,CAC7E;IACH,CAAC,MAAM,IAAIJ,OAAO,CAACE,SAAS,IAAIF,OAAO,CAACA,OAAO,EAAE;AAC/C,MAAA,MAAM,IAAIG,cAAc,CACtBC,4BAA4B,EAC5B,mFAAmF,CACpF;AACH,IAAA;IAEAH,KAAA,GAAAJ,MAAK,CAAAQ,IAAA,CAAA,IAAA,EAACN,IAAI,EAAE;AACVO,MAAAA,OAAO,EAAEC,gBAAgB;MACzBC,YAAY,EAAER,OAAO,CAACE,SAAS,GAAGF,OAAO,CAACE,SAAS,GAAGO,eAAe,uBAAMT,OAAO,CAACA,OAAO,CAAA,EAAA;AAAEU,QAAAA,QAAQ,EAAE;AAAE,OAAA,CAAA;KACzG,CAAC,IAAA,IAAA;IAxBMT,KAAA,CAAAU,SAAS,GAAY,KAAK;AA0BlCV,IAAAA,KAAI,CAACD,OAAO,GAAGA,OAAO,CAACA,OAAO;;AAQhC,EAAA;AAEOJ,EAAAA,iBAAA,CAAAgB,SAAA,CAAAC,aAAa,GAApB,YAAA;;IACE,IAAI,IAAI,CAACb,OAAO,EAAE;MAChB,IAAI,IAAI,CAACW,SAAS,EAAE;QAKlB,IAAI,CAACG,KAAK,GAAGL,eAAe,CAAC,IAAI,CAACT,OAAO,CAAC;QAC1C,IAAI,CAACW,SAAS,GAAG,KAAK;AACxB,MAAA,CAAC,MAAM;QACL,IAAI,MAAA,IAAI,CAACX,OAAO,MAAA,IAAA,IAAAe,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAEL,QAAQ,EAAE;UAK1B,KAAoB,IAAAM,EAAA,GAAA,CAAqB,EAArBC,EAAA,GAAA,IAAI,CAACjB,OAAO,CAACU,QAAQ,EAArBM,EAAA,GAAAC,EAAA,CAAAC,MAAqB,EAArBF,EAAA,EAAqB,EAAE;AAAtC,YAAA,IAAMG,KAAK,GAAAF,EAAA,CAAAD,EAAA,CAAA;AACd,YAAA,IAAI,CAACF,KAAK,CAACM,GAAG,CAACD,KAAK,CAAC;AACvB,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;IAEAtB,MAAA,CAAAe,SAAK,CAACC,aAAa,CAAAR,IAAA,CAAA,IAAA,CAAE;EACvB,CAAC;AAEMT,EAAAA,iBAAA,CAAAgB,SAAA,CAAAS,gBAAgB,GAAvB,YAAA;IACE,IAAI,IAAI,CAACrB,OAAO,EAAE;AAKhB,MAAA,IAAI,CAACc,KAAK,CAACQ,SAAS,EAAE;MACtB,IAAI,CAACX,SAAS,GAAG,IAAI;AACvB,IAAA;EACF,CAAC;AACH,EAAA,OAAAf,iBAAC;AAAD,CA7EA,CACU2B,eAAe;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SubContainerProvider } from './sub-container-provider.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that provides a managed child container derived from the nearest
|
|
5
|
+
* parent container context.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The child container is created from the current parent context when the host
|
|
9
|
+
* connects, destroyed when it disconnects, and recreated when the parent
|
|
10
|
+
* container changes.
|
|
11
|
+
*
|
|
12
|
+
* @group Provision
|
|
13
|
+
*
|
|
14
|
+
* @param options - Provisioning options.
|
|
15
|
+
* @param options.options - Child-container creation options.
|
|
16
|
+
* @returns An instance of {@link SubContainerProviderDecorator}.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* class MyComponent extends LitElement {
|
|
21
|
+
* @subContainerProvide({
|
|
22
|
+
* options: {
|
|
23
|
+
* entries: [AuthService, UserService],
|
|
24
|
+
* activate: [AuthService],
|
|
25
|
+
* },
|
|
26
|
+
* })
|
|
27
|
+
* public containerProvider!: SubContainerProvider<MyComponent>;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function subContainerProvide(options) {
|
|
32
|
+
return function (protoOrTarget, nameOrContext) {
|
|
33
|
+
if (typeof nameOrContext === "object") {
|
|
34
|
+
// Standard decorators:
|
|
35
|
+
nameOrContext.addInitializer(function () {
|
|
36
|
+
protoOrTarget.set.call(this, new SubContainerProvider(this, options));
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
var provider_1;
|
|
40
|
+
protoOrTarget.constructor.addInitializer(function (element) {
|
|
41
|
+
provider_1 = new SubContainerProvider(element, options);
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
get: function () {
|
|
45
|
+
return provider_1;
|
|
46
|
+
},
|
|
47
|
+
set: function () {},
|
|
48
|
+
configurable: true,
|
|
49
|
+
enumerable: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { subContainerProvide };
|
|
56
|
+
//# sourceMappingURL=sub-container-provide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-container-provide.js","sources":["../../../../../../../../src/wirestate-lit/provision/sub-container-provide.ts"],"sourcesContent":[null],"names":["subContainerProvide","options","protoOrTarget","nameOrContext","addInitializer","set","call","SubContainerProvider","provider_1","constructor","element","get","configurable","enumerable"],"mappings":";;AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACG,SAAUA,mBAAmBA,CACjCC,OAAoC,EAAA;AAEpC,EAAA,OAAQ,UACNC,aAAmG,EACnGC,aAAkH,EAAA;AAElH,IAAA,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAE;AACrC;MACAA,aAAa,CAACC,cAAc,CAAC,YAAA;AAC3BF,QAAAA,aAAa,CAACG,GAAG,CAACC,IAAI,CAAC,IAAI,EAAE,IAAIC,oBAAoB,CAAC,IAAuB,EAAEN,OAAO,CAAC,CAAC;AAC1F,MAAA,CAAC,CAAC;AACJ,IAAA,CAAC,MAAM;AACL,MAAA,IAAIO,UAAwC;AAE3CN,MAAAA,aAAa,CAACO,WAAsC,CAACL,cAAc,CAAC,UAACM,OAAwB,EAAA;AAC5FF,QAAAA,UAAQ,GAAG,IAAID,oBAAoB,CAACG,OAAY,EAAET,OAAO,CAAC;AAC5D,MAAA,CAAC,CAAC;MAEF,OAAO;QACLU,GAAG,EAAA,YAAA;AACD,UAAA,OAAOH,UAAmC;QAC5C,CAAC;AACDH,QAAAA,GAAG,eAAU,CAAC;AACdO,QAAAA,YAAY,EAAE,IAAI;AAClBC,QAAAA,UAAU,EAAE;OACb;AACH,IAAA;EACF,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __extends, __assign } from 'tslib';
|
|
2
|
+
import { ContextConsumer, ContextProvider } from '@lit/context';
|
|
3
|
+
import { createContainer } from '@wirestate/core';
|
|
4
|
+
import { ContainerContext } from '../context/container-context.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Provider that exposes a managed child container for the host element's lifetime.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The provider always owns a child container derived from the nearest parent
|
|
11
|
+
* {@link ContainerContext}. When connected, it creates a child container using
|
|
12
|
+
* the latest parent context, provides it to descendants, destroys it when the
|
|
13
|
+
* host disconnects, and replaces it whenever the parent container changes.
|
|
14
|
+
*
|
|
15
|
+
* @group Provision
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* class MyComponent extends LitElement {
|
|
20
|
+
* private container = new SubContainerProvider(this, {
|
|
21
|
+
* options: {
|
|
22
|
+
* entries: [AuthService, UserService],
|
|
23
|
+
* activate: [AuthService],
|
|
24
|
+
* seeds: [[AuthService, { role: "admin" }]],
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
var SubContainerProvider = /** @class */function (_super) {
|
|
31
|
+
__extends(SubContainerProvider, _super);
|
|
32
|
+
/**
|
|
33
|
+
* @param host - The host element.
|
|
34
|
+
* @param options - Provisioning options, including child entries, eager activations, and seeds.
|
|
35
|
+
*/
|
|
36
|
+
function SubContainerProvider(host, options) {
|
|
37
|
+
var _this = _super.call(this, host, {
|
|
38
|
+
context: ContainerContext
|
|
39
|
+
}) || this;
|
|
40
|
+
_this.parent = null;
|
|
41
|
+
_this.destroyed = true;
|
|
42
|
+
_this.options = options.options;
|
|
43
|
+
_this.consumer = new ContextConsumer(host, {
|
|
44
|
+
context: ContainerContext,
|
|
45
|
+
subscribe: true,
|
|
46
|
+
callback: function (context) {
|
|
47
|
+
var previousParent = _this.parent;
|
|
48
|
+
_this.parent = context;
|
|
49
|
+
if (host.isConnected) {
|
|
50
|
+
if (_this.destroyed || !_this.value || previousParent !== context) {
|
|
51
|
+
_this.destroyContainer();
|
|
52
|
+
_this.createContainer();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return _this;
|
|
58
|
+
}
|
|
59
|
+
SubContainerProvider.prototype.hostConnected = function () {
|
|
60
|
+
if (this.parent && (this.destroyed || !this.value)) {
|
|
61
|
+
this.destroyContainer();
|
|
62
|
+
this.createContainer();
|
|
63
|
+
}
|
|
64
|
+
_super.prototype.hostConnected.call(this);
|
|
65
|
+
};
|
|
66
|
+
SubContainerProvider.prototype.hostDisconnected = function () {
|
|
67
|
+
this.destroyContainer();
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the currently provided child container with a new one derived
|
|
71
|
+
* from the latest parent context.
|
|
72
|
+
*/
|
|
73
|
+
SubContainerProvider.prototype.createContainer = function () {
|
|
74
|
+
var container = createContainer(__assign(__assign({}, this.options), {
|
|
75
|
+
parent: this.parent
|
|
76
|
+
}));
|
|
77
|
+
this.destroyed = false;
|
|
78
|
+
this.value = container;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Destroys the currently provided child container.
|
|
82
|
+
*/
|
|
83
|
+
SubContainerProvider.prototype.destroyContainer = function () {
|
|
84
|
+
if (this.value && !this.destroyed) {
|
|
85
|
+
this.value.unbindAll();
|
|
86
|
+
this.destroyed = true;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return SubContainerProvider;
|
|
90
|
+
}(ContextProvider);
|
|
91
|
+
|
|
92
|
+
export { SubContainerProvider };
|
|
93
|
+
//# sourceMappingURL=sub-container-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-container-provider.js","sources":["../../../../../../../../src/wirestate-lit/provision/sub-container-provider.ts"],"sourcesContent":[null],"names":["SubContainerProvider","_super","__extends","host","options","_this","call","context","ContainerContext","parent","destroyed","consumer","ContextConsumer","subscribe","callback","previousParent","isConnected","value","destroyContainer","createContainer","prototype","hostConnected","hostDisconnected","container","__assign","unbindAll","ContextProvider"],"mappings":";;;;;AAkDA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACH,IAAAA,oBAAA,gBAAA,UAAAC,MAAA,EAAA;AACUC,EAAAA,SAAA,CAAAF,oBAAA,EAAAC,MAAA,CAAA;AASR;;;AAGG;AACH,EAAA,SAAAD,oBAAAA,CAAmBG,IAAO,EAAEC,OAAoC,EAAA;IAC9D,IAAAC,KAAA,GAAAJ,MAAK,CAAAK,IAAA,CAAA,IAAA,EAACH,IAAI,EAAE;AACVI,MAAAA,OAAO,EAAEC;KACV,CAAC,IAAA,IAAA;IAVMH,KAAA,CAAAI,MAAM,GAAqB,IAAI;IAC/BJ,KAAA,CAAAK,SAAS,GAAY,IAAI;AAajCL,IAAAA,KAAI,CAACD,OAAO,GAAGA,OAAO,CAACA,OAAO;AAE9BC,IAAAA,KAAI,CAACM,QAAQ,GAAG,IAAIC,eAAe,CAACT,IAAI,EAAE;AACxCI,MAAAA,OAAO,EAAEC,gBAAgB;AACzBK,MAAAA,SAAS,EAAE,IAAI;AACfC,MAAAA,QAAQ,EAAE,UAACP,OAAkB,EAAA;AAC3B,QAAA,IAAMQ,cAAc,GAAqBV,KAAI,CAACI,MAAM;QAEpDJ,KAAI,CAACI,MAAM,GAAGF,OAAO;QAErB,IAAIJ,IAAI,CAACa,WAAW,EAAE;AAMpB,UAAA,IAAIX,KAAI,CAACK,SAAS,IAAI,CAACL,KAAI,CAACY,KAAK,IAAIF,cAAc,KAAKR,OAAO,EAAE;YAC/DF,KAAI,CAACa,gBAAgB,EAAE;YACvBb,KAAI,CAACc,eAAe,EAAE;AACxB,UAAA;AACF,QAAA;AAMF,MAAA;AACD,KAAA,CAAC;;AACJ,EAAA;AAEOnB,EAAAA,oBAAA,CAAAoB,SAAA,CAAAC,aAAa,GAApB,YAAA;AAOE,IAAA,IAAI,IAAI,CAACZ,MAAM,KAAK,IAAI,CAACC,SAAS,IAAI,CAAC,IAAI,CAACO,KAAK,CAAC,EAAE;MAClD,IAAI,CAACC,gBAAgB,EAAE;MACvB,IAAI,CAACC,eAAe,EAAE;AACxB,IAAA;IAEAlB,MAAA,CAAAmB,SAAK,CAACC,aAAa,CAAAf,IAAA,CAAA,IAAA,CAAE;EACvB,CAAC;AAEMN,EAAAA,oBAAA,CAAAoB,SAAA,CAAAE,gBAAgB,GAAvB,YAAA;IAOE,IAAI,CAACJ,gBAAgB,EAAE;EACzB,CAAC;AAED;;;AAGG;AACOlB,EAAAA,oBAAA,CAAAoB,SAAA,CAAAD,eAAe,GAAzB,YAAA;AACE,IAAA,IAAMI,SAAS,GAAcJ,eAAe,CAAAK,QAAA,CAAAA,QAAA,CAAA,EAAA,EACvC,IAAI,CAACpB,OAAO,CAAA,EAAA;MACfK,MAAM,EAAE,IAAI,CAACA;OACb;IAQF,IAAI,CAACC,SAAS,GAAG,KAAK;IACtB,IAAI,CAACO,KAAK,GAAGM,SAAS;EACxB,CAAC;AAED;;AAEG;AACOvB,EAAAA,oBAAA,CAAAoB,SAAA,CAAAF,gBAAgB,GAA1B,YAAA;IACE,IAAI,IAAI,CAACD,KAAK,IAAI,CAAC,IAAI,CAACP,SAAS,EAAE;AAMjC,MAAA,IAAI,CAACO,KAAK,CAACQ,SAAS,EAAE;MACtB,IAAI,CAACf,SAAS,GAAG,IAAI;AACvB,IAAA;EACF,CAAC;AACH,EAAA,OAAAV,oBAAC;AAAD,CA9GA,CACU0B,eAAe;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ContainerProvider } from './container-provider.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides a container to the host element and its children.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pass `container` to expose an external `Container` without taking
|
|
8
|
+
* ownership. Pass `options` to create a managed container during
|
|
9
|
+
* construction, activate configured entries on connect, destroy it on
|
|
10
|
+
* disconnect, and recreate it on reconnect.
|
|
11
|
+
*
|
|
12
|
+
* @group Provision
|
|
13
|
+
*
|
|
14
|
+
* @param host - The host element.
|
|
15
|
+
* @param options - Provisioning options.
|
|
16
|
+
* @param options.container - External container instance to provide.
|
|
17
|
+
* @param options.options - Managed container creation options.
|
|
18
|
+
* @returns An instance of {@link ContainerProvider}.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class MyRootElement extends LitElement {
|
|
23
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, {
|
|
24
|
+
* options: {
|
|
25
|
+
* entries: [LoggerService],
|
|
26
|
+
* activate: [LoggerService],
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* class MyRootElement extends LitElement {
|
|
35
|
+
* private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function useContainerProvision(host, options) {
|
|
40
|
+
return new ContainerProvider(host, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { useContainerProvision };
|
|
44
|
+
//# sourceMappingURL=use-container-provision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-container-provision.js","sources":["../../../../../../../../src/wirestate-lit/provision/use-container-provision.ts"],"sourcesContent":[null],"names":["useContainerProvision","host","options","ContainerProvider"],"mappings":";;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;AACG,SAAUA,qBAAqBA,CACnCC,IAAO,EACPC,OAAqC,EAAA;AAErC,EAAA,OAAO,IAAIC,iBAAiB,CAACF,IAAI,EAAEC,OAAO,CAAC;AAC7C;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SubContainerProvider } from './sub-container-provider.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides a managed child container for the host element's lifetime.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The child container is derived from the current parent
|
|
8
|
+
* {@link ContainerContext}, recreated when that parent context changes, and
|
|
9
|
+
* destroyed when the host disconnects.
|
|
10
|
+
*
|
|
11
|
+
* @group Provision
|
|
12
|
+
*
|
|
13
|
+
* @param host - The host element.
|
|
14
|
+
* @param options - Provisioning options.
|
|
15
|
+
* @param options.options - Child-container creation options.
|
|
16
|
+
* @returns An instance of {@link SubContainerProvider}.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* class MyComponent extends LitElement {
|
|
21
|
+
* private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
|
|
22
|
+
* options: {
|
|
23
|
+
* entries: [AuthService, UserService],
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function useSubContainerProvider(host, options) {
|
|
30
|
+
return new SubContainerProvider(host, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { useSubContainerProvider };
|
|
34
|
+
//# sourceMappingURL=use-sub-container-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-sub-container-provider.js","sources":["../../../../../../../../src/wirestate-lit/provision/use-sub-container-provider.ts"],"sourcesContent":[null],"names":["useSubContainerProvider","host","options","SubContainerProvider"],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACG,SAAUA,uBAAuBA,CACrCC,IAAO,EACPC,OAAoC,EAAA;AAEpC,EAAA,OAAO,IAAIC,oBAAoB,CAAIF,IAAI,EAAEC,OAAO,CAAC;AACnD;;;;"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { ContextConsumer } from '@lit/context';
|
|
2
2
|
import { QueryBus } from '@wirestate/core';
|
|
3
|
-
import { ContainerContext } from '../context/
|
|
3
|
+
import { ContainerContext } from '../context/container-context.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Reactive controller that registers a query handler on the {@link QueryBus} for the host element's lifetime.
|
|
7
7
|
*
|
|
8
|
+
* @remarks
|
|
8
9
|
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
9
|
-
*
|
|
10
|
+
* It automatically re-registers if the IoC container is updated.
|
|
10
11
|
*
|
|
11
|
-
* @group
|
|
12
|
+
* @group Queries
|
|
12
13
|
*/
|
|
13
14
|
var OnQueryController = /** @class */function () {
|
|
14
15
|
/**
|
|
15
|
-
* @param host -
|
|
16
|
-
* @param type - the query
|
|
17
|
-
* @param handler -
|
|
16
|
+
* @param host - The host element.
|
|
17
|
+
* @param type - Unique identifier of the query to handle.
|
|
18
|
+
* @param handler - The query handler function.
|
|
18
19
|
*/
|
|
19
20
|
function OnQueryController(host, type, handler) {
|
|
20
21
|
var _this = this;
|
|
@@ -26,8 +27,8 @@ var OnQueryController = /** @class */function () {
|
|
|
26
27
|
new ContextConsumer(host, {
|
|
27
28
|
context: ContainerContext,
|
|
28
29
|
subscribe: true,
|
|
29
|
-
callback: function (
|
|
30
|
-
_this.bus =
|
|
30
|
+
callback: function (container) {
|
|
31
|
+
_this.bus = container.get(QueryBus);
|
|
31
32
|
if (host.isConnected) {
|
|
32
33
|
_this.reregister();
|
|
33
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-query-controller.js","sources":["../../../../../../../../src/wirestate-lit/queries/on-query-controller.ts"],"sourcesContent":[null],"names":["OnQueryController","host","type","handler","_this","bus","unregister","addController","ContextConsumer","context","ContainerContext","subscribe","callback","container","get","QueryBus","isConnected","reregister","prototype","hostConnected","hostDisconnected","cleanup","register","_a","call"],"mappings":";;;;AAUA
|
|
1
|
+
{"version":3,"file":"on-query-controller.js","sources":["../../../../../../../../src/wirestate-lit/queries/on-query-controller.ts"],"sourcesContent":[null],"names":["OnQueryController","host","type","handler","_this","bus","unregister","addController","ContextConsumer","context","ContainerContext","subscribe","callback","container","get","QueryBus","isConnected","reregister","prototype","hostConnected","hostDisconnected","cleanup","register","_a","call"],"mappings":";;;;AAUA;;;;;;;;AAQG;AACH,IAAAA,iBAAA,gBAAA,YAAA;AAOE;;;;AAIG;AACH,EAAA,SAAAA,iBAAAA,CAAmBC,IAAqB,EAAEC,IAAe,EAAEC,OAA2B,EAAA;IAAtF,IAAAC,KAAA,GAAA,IAAA;IAXQ,IAAA,CAAAC,GAAG,GAAuB,IAAI;IAC9B,IAAA,CAAAC,UAAU,GAA8B,IAAI;AAWlDL,IAAAA,IAAI,CAACM,aAAa,CAAC,IAAI,CAAC;IAExB,IAAI,CAACL,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;IAItB,IAAIK,eAAe,CAACP,IAAI,EAAE;AACxBQ,MAAAA,OAAO,EAAEC,gBAAgB;AACzBC,MAAAA,SAAS,EAAE,IAAI;AACfC,MAAAA,QAAQ,EAAE,UAACC,SAAS,EAAA;QAClBT,KAAI,CAACC,GAAG,GAAGQ,SAAS,CAACC,GAAG,CAACC,QAAQ,CAAC;QAElC,IAAId,IAAI,CAACe,WAAW,EAAE;UACpBZ,KAAI,CAACa,UAAU,EAAE;AACnB,QAAA;AACF,MAAA;AACD,KAAA,CAAC;AACJ,EAAA;AAEOjB,EAAAA,iBAAA,CAAAkB,SAAA,CAAAC,aAAa,GAApB,YAAA;IAEE,IAAI,CAACF,UAAU,EAAE;EACnB,CAAC;AAEMjB,EAAAA,iBAAA,CAAAkB,SAAA,CAAAE,gBAAgB,GAAvB,YAAA;IAEE,IAAI,CAACC,OAAO,EAAE;EAChB,CAAC;AAEOrB,EAAAA,iBAAA,CAAAkB,SAAA,CAAAD,UAAU,GAAlB,YAAA;IACE,IAAI,CAACI,OAAO,EAAE;IAEd,IAAI,IAAI,CAAChB,GAAG,EAAE;AAEZ,MAAA,IAAI,CAACC,UAAU,GAAG,IAAI,CAACD,GAAG,CAACiB,QAAQ,CAAC,IAAI,CAACpB,IAAI,EAAE,IAAI,CAACC,OAAO,CAAC;AAC9D,IAAA;EACF,CAAC;AAEOH,EAAAA,iBAAA,CAAAkB,SAAA,CAAAG,OAAO,GAAf,YAAA;;IACE,CAAAE,EAAA,GAAA,IAAI,CAACjB,UAAU,MAAA,IAAA,IAAAiB,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAA,IAAA,CAAI;IACnB,IAAI,CAAClB,UAAU,GAAG,IAAI;EACxB,CAAC;AACH,EAAA,OAAAN,iBAAC;AAAD,CAAC;;;;"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { OnQueryController } from './on-query-controller.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Decorator
|
|
4
|
+
* Decorator for Lit element methods that handle a specific query.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The handler is registered when the host connects and unregistered when it disconnects.
|
|
7
8
|
*
|
|
8
|
-
* @group
|
|
9
|
+
* @group Queries
|
|
9
10
|
*
|
|
10
|
-
* @param type - the query
|
|
11
|
-
* @returns
|
|
11
|
+
* @param type - Unique identifier of the query to handle.
|
|
12
|
+
* @returns A method decorator function.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
16
|
* class MyElement extends LitElement {
|
|
16
17
|
* @onQuery("GET_USER_NAME")
|
|
17
|
-
*
|
|
18
|
+
* private onGetUserName(data: QueryData) {
|
|
18
19
|
* return "Alice";
|
|
19
20
|
* }
|
|
20
21
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-query.js","sources":["../../../../../../../../src/wirestate-lit/queries/on-query.ts"],"sourcesContent":[null],"names":["onQuery","type","protoOrTarget","nameOrContext","addInitializer","_this","OnQueryController","data","name","constructor","element"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"on-query.js","sources":["../../../../../../../../src/wirestate-lit/queries/on-query.ts"],"sourcesContent":[null],"names":["onQuery","type","protoOrTarget","nameOrContext","addInitializer","_this","OnQueryController","data","name","constructor","element"],"mappings":";;AAyBA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAUA,OAAOA,CAA2BC,IAAe,EAAA;AAC/D,EAAA,OAAQ,UAACC,aAAqB,EAAEC,aAAwD,EAAA;AACtF,IAAA,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAE;AACrC;MACAA,aAAa,CAACC,cAAc,CAAC,YAAA;QAAA,IAAAC,KAAA,GAAA,IAAA;QAC3B,IAAIC,iBAAiB,CACnB,IAAuB,EACvBL,IAAI,EACJ,UAACM,IAAO,EAAA;UAAK,OAACF,KAAkB,CAACF,aAAa,CAACK,IAAI,CAAC,CAACD,IAAI,CAAoB;AAAhE,QAAA,CAAgE,CAC9E;AACH,MAAA,CAAC,CAAC;AACJ,IAAA,CAAC,MAAM;AACL;AACCL,MAAAA,aAAa,CAACO,WAAsC,CAACL,cAAc,CAAC,UAACM,OAAwB,EAAA;QAC5F,IAAIJ,iBAAiB,CACnBI,OAAO,EACPT,IAAI,EACJ,UAACM,IAAO,EAAA;AAAK,UAAA,OAACG,OAAqB,CAACP,aAAa,CAAC,CAACI,IAAI,CAAoB;AAA9D,QAAA,CAA8D,CAC5E;AACH,MAAA,CAAC,CAAC;AACJ,IAAA;EACF,CAAC;AACH;;;;"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { OnQueryController } from './on-query-controller.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook that registers a query handler for the host element's lifetime.
|
|
5
5
|
*
|
|
6
|
-
* @group
|
|
6
|
+
* @group Queries
|
|
7
7
|
*
|
|
8
|
-
* @param host -
|
|
9
|
-
* @param options -
|
|
10
|
-
* @param options.type -
|
|
11
|
-
* @param options.handler -
|
|
12
|
-
* @returns
|
|
8
|
+
* @param host - The host element.
|
|
9
|
+
* @param options - Query handling options.
|
|
10
|
+
* @param options.type - The query type to handle.
|
|
11
|
+
* @param options.handler - The query handler function.
|
|
12
|
+
* @returns An instance of {@link OnQueryController}.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|