@wirestate/lit 0.7.0-experimental.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +49 -31
  3. package/cjs/development/index.js +326 -241
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/production/index.js +1 -1
  6. package/cjs/production/index.js.map +1 -1
  7. package/esm/development/commands/on-command-controller.js +4 -4
  8. package/esm/development/commands/on-command-controller.js.map +1 -1
  9. package/esm/development/consumption/injection.js +7 -7
  10. package/esm/development/consumption/injection.js.map +1 -1
  11. package/esm/development/consumption/use-container.js +40 -0
  12. package/esm/development/consumption/use-container.js.map +1 -0
  13. package/esm/development/consumption/use-injection.js +4 -4
  14. package/esm/development/consumption/use-injection.js.map +1 -1
  15. package/esm/development/consumption/use-scope.js +44 -0
  16. package/esm/development/consumption/use-scope.js.map +1 -0
  17. package/esm/development/context/container-context.js +17 -0
  18. package/esm/development/context/container-context.js.map +1 -0
  19. package/esm/development/events/on-event-controller.js +4 -4
  20. package/esm/development/events/on-event-controller.js.map +1 -1
  21. package/esm/development/index.js +9 -7
  22. package/esm/development/index.js.map +1 -1
  23. package/esm/development/provision/container-provide.js +68 -0
  24. package/esm/development/provision/container-provide.js.map +1 -0
  25. package/esm/development/provision/container-provider.js +74 -0
  26. package/esm/development/provision/container-provider.js.map +1 -0
  27. package/esm/development/provision/sub-container-provide.js +56 -0
  28. package/esm/development/provision/sub-container-provide.js.map +1 -0
  29. package/esm/development/provision/sub-container-provider.js +93 -0
  30. package/esm/development/provision/sub-container-provider.js.map +1 -0
  31. package/esm/development/provision/use-container-provision.js +44 -0
  32. package/esm/development/provision/use-container-provision.js.map +1 -0
  33. package/esm/development/provision/use-sub-container-provider.js +34 -0
  34. package/esm/development/provision/use-sub-container-provider.js.map +1 -0
  35. package/esm/development/queries/on-query-controller.js +4 -4
  36. package/esm/development/queries/on-query-controller.js.map +1 -1
  37. package/esm/production/commands/on-command-controller.js +1 -1
  38. package/esm/production/commands/on-command-controller.js.map +1 -1
  39. package/esm/production/consumption/injection.js +1 -1
  40. package/esm/production/consumption/injection.js.map +1 -1
  41. package/esm/production/consumption/use-container.js +1 -0
  42. package/esm/production/consumption/use-container.js.map +1 -0
  43. package/esm/production/consumption/use-injection.js +1 -1
  44. package/esm/production/consumption/use-injection.js.map +1 -1
  45. package/esm/production/consumption/use-scope.js +1 -0
  46. package/esm/production/consumption/use-scope.js.map +1 -0
  47. package/esm/production/context/container-context.js +1 -0
  48. package/esm/production/context/container-context.js.map +1 -0
  49. package/esm/production/events/on-event-controller.js +1 -1
  50. package/esm/production/events/on-event-controller.js.map +1 -1
  51. package/esm/production/index.js +1 -1
  52. package/esm/production/provision/container-provide.js +1 -0
  53. package/esm/production/provision/container-provide.js.map +1 -0
  54. package/esm/production/provision/container-provider.js +1 -0
  55. package/esm/production/provision/container-provider.js.map +1 -0
  56. package/esm/production/provision/sub-container-provide.js +1 -0
  57. package/esm/production/provision/sub-container-provide.js.map +1 -0
  58. package/esm/production/provision/sub-container-provider.js +1 -0
  59. package/esm/production/provision/sub-container-provider.js.map +1 -0
  60. package/esm/production/provision/use-container-provision.js +1 -0
  61. package/esm/production/provision/use-container-provision.js.map +1 -0
  62. package/esm/production/provision/use-sub-container-provider.js +1 -0
  63. package/esm/production/provision/use-sub-container-provider.js.map +1 -0
  64. package/esm/production/queries/on-query-controller.js +1 -1
  65. package/esm/production/queries/on-query-controller.js.map +1 -1
  66. package/index.d.ts +271 -176
  67. package/package.json +2 -2
  68. package/esm/development/context/ioc-context.js +0 -17
  69. package/esm/development/context/ioc-context.js.map +0 -1
  70. package/esm/development/provision/injectables-provide.js +0 -47
  71. package/esm/development/provision/injectables-provide.js.map +0 -1
  72. package/esm/development/provision/injectables-provider-controller.js +0 -123
  73. package/esm/development/provision/injectables-provider-controller.js.map +0 -1
  74. package/esm/development/provision/ioc-provide.js +0 -58
  75. package/esm/development/provision/ioc-provide.js.map +0 -1
  76. package/esm/development/provision/ioc-provider-controller.js +0 -75
  77. package/esm/development/provision/ioc-provider-controller.js.map +0 -1
  78. package/esm/development/provision/use-injectables-provider.js +0 -27
  79. package/esm/development/provision/use-injectables-provider.js.map +0 -1
  80. package/esm/development/provision/use-ioc-provision.js +0 -27
  81. package/esm/development/provision/use-ioc-provision.js.map +0 -1
  82. package/esm/production/context/ioc-context.js +0 -1
  83. package/esm/production/context/ioc-context.js.map +0 -1
  84. package/esm/production/provision/injectables-provide.js +0 -1
  85. package/esm/production/provision/injectables-provide.js.map +0 -1
  86. package/esm/production/provision/injectables-provider-controller.js +0 -1
  87. package/esm/production/provision/injectables-provider-controller.js.map +0 -1
  88. package/esm/production/provision/ioc-provide.js +0 -1
  89. package/esm/production/provision/ioc-provide.js.map +0 -1
  90. package/esm/production/provision/ioc-provider-controller.js +0 -1
  91. package/esm/production/provision/ioc-provider-controller.js.map +0 -1
  92. package/esm/production/provision/use-injectables-provider.js +0 -1
  93. package/esm/production/provision/use-injectables-provider.js.map +0 -1
  94. package/esm/production/provision/use-ioc-provision.js +0 -1
  95. package/esm/production/provision/use-ioc-provision.js.map +0 -1
@@ -9,13 +9,13 @@ var tslib = require('tslib');
9
9
  *
10
10
  * @group Context
11
11
  */
12
- var IOC_CONTAINER_KEY = Symbol("ContainerContext");
12
+ var CONTAINER_KEY = Symbol("ContainerContext");
13
13
  /**
14
- * Lit context object for providing and consuming the IoC container.
14
+ * Lit context object for providing and consuming the container.
15
15
  *
16
16
  * @group Context
17
17
  */
18
- var IocContextObject = context.createContext(IOC_CONTAINER_KEY);
18
+ var ContainerContext = context.createContext(CONTAINER_KEY);
19
19
 
20
20
  /**
21
21
  * Decorator to inject a service from the IoC container into a Lit element property.
@@ -61,9 +61,9 @@ function injection(optionsOrInjectionId) {
61
61
  nameOrContext.addInitializer(function () {
62
62
  var _this = this;
63
63
  new context.ContextConsumer(this, {
64
- context: IocContextObject,
65
- callback: function (it) {
66
- protoOrTarget.set.call(_this, it.container.get(injectionId));
64
+ context: ContainerContext,
65
+ callback: function (container) {
66
+ protoOrTarget.set.call(_this, container.get(injectionId));
67
67
  },
68
68
  subscribe: !once
69
69
  });
@@ -72,9 +72,9 @@ function injection(optionsOrInjectionId) {
72
72
  // Experimental decorators branch.
73
73
  protoOrTarget.constructor.addInitializer(function (element) {
74
74
  new context.ContextConsumer(element, {
75
- context: IocContextObject,
76
- callback: function (it) {
77
- element[nameOrContext] = it.container.get(injectionId);
75
+ context: ContainerContext,
76
+ callback: function (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
+ var current = {
110
+ value: null
111
+ };
112
+ new context.ContextConsumer(host, {
113
+ context: ContainerContext,
114
+ callback: function (container) {
115
+ current.value = container;
116
+ }
117
+ });
118
+ return current;
119
+ }
120
+
86
121
  /**
87
122
  * Hook (controller) to inject a service from the IoC container.
88
123
  *
@@ -126,10 +161,48 @@ function useInjection(host, optionsOrInjectionId) {
126
161
  injectionId: injectionId
127
162
  };
128
163
  new context.ContextConsumer(host, {
129
- context: IocContextObject,
164
+ context: ContainerContext,
130
165
  subscribe: !once,
131
- callback: function (it) {
132
- current.value = it.container.get(injectionId);
166
+ callback: function (container) {
167
+ current.value = container.get(injectionId);
168
+ }
169
+ });
170
+ return current;
171
+ }
172
+
173
+ /**
174
+ * Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
175
+ *
176
+ * @remarks
177
+ * The returned value updates when the nearest provided container changes.
178
+ *
179
+ * @group Consumption
180
+ *
181
+ * @param host - The host element.
182
+ * @returns An instance of {@link UseScopeValue}.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * class MyElement extends LitElement {
187
+ * private scope: UseScopeValue = useScope(this);
188
+ *
189
+ * public connectedCallback(): void {
190
+ * super.connectedCallback();
191
+ * this.scope.value.emitEvent("UI_READY");
192
+ * }
193
+ * }
194
+ * ```
195
+ */
196
+ function useScope(host) {
197
+ var current = {
198
+ value: undefined,
199
+ injectionId: core.WireScope
200
+ };
201
+ new context.ContextConsumer(host, {
202
+ context: ContainerContext,
203
+ subscribe: true,
204
+ callback: function (container) {
205
+ current.value = container.get(core.WireScope);
133
206
  }
134
207
  });
135
208
  return current;
@@ -158,10 +231,10 @@ var OnCommandController = /** @class */function () {
158
231
  this.type = type;
159
232
  this.handler = handler;
160
233
  new context.ContextConsumer(host, {
161
- context: IocContextObject,
234
+ context: ContainerContext,
162
235
  subscribe: true,
163
- callback: function (context) {
164
- _this.bus = context.container.get(core.CommandBus);
236
+ callback: function (container) {
237
+ _this.bus = container.get(core.CommandBus);
165
238
  if (host.isConnected) {
166
239
  _this.reregister();
167
240
  }
@@ -280,10 +353,10 @@ var OnEventController = /** @class */function () {
280
353
  this.types = types;
281
354
  this.handler = handler;
282
355
  new context.ContextConsumer(host, {
283
- context: IocContextObject,
356
+ context: ContainerContext,
284
357
  subscribe: true,
285
- callback: function (context) {
286
- _this.bus = context.container.get(core.EventBus);
358
+ callback: function (container) {
359
+ _this.bus = container.get(core.EventBus);
287
360
  if (host.isConnected) {
288
361
  _this.resubscribe();
289
362
  }
@@ -442,10 +515,10 @@ var OnQueryController = /** @class */function () {
442
515
  this.type = type;
443
516
  this.handler = handler;
444
517
  new context.ContextConsumer(host, {
445
- context: IocContextObject,
518
+ context: ContainerContext,
446
519
  subscribe: true,
447
- callback: function (context) {
448
- _this.bus = context.container.get(core.QueryBus);
520
+ callback: function (container) {
521
+ _this.bus = container.get(core.QueryBus);
449
522
  if (host.isConnected) {
450
523
  _this.reregister();
451
524
  }
@@ -541,116 +614,211 @@ function useOnQuery(host, _a) {
541
614
  return new OnQueryController(host, type, handler);
542
615
  }
543
616
 
617
+ var ERROR_CODE_INVALID_ARGUMENTS = 2051;
618
+
544
619
  /**
545
- * Controller that provides an IoC container context to the host element and its children.
620
+ * Provider that exposes an IoC container context to the host element and its children.
546
621
  *
547
622
  * @remarks
548
- * It manages the lifecycle of the container and handles revision updates to notify consumers.
549
- * The container is created (or used from options) when the controller is instantiated.
550
- * Seed data is applied when the host connects.
623
+ * The provider supports two modes:
624
+ *
625
+ * - External mode: `container` is an existing {@link Container}. The
626
+ * provider passes it through context and does not alter its lifecycle.
627
+ * - Managed mode: `options` is {@link CreateContainerOptions}. The provider
628
+ * creates a container during construction without eager activation,
629
+ * activates configured entries when the host connects, disposes the
630
+ * container when the host disconnects, and recreates it on reconnect.
551
631
  *
552
632
  * @group Provision
553
633
  */
554
- var IocProviderController = /** @class */function () {
634
+ var ContainerProvider = /** @class */function (_super) {
635
+ tslib.__extends(ContainerProvider, _super);
555
636
  /**
556
637
  * @param host - The host element.
557
638
  * @param options - Provisioning options.
558
- * @param options.container - Optional existing container to use. If not provided, a new one will be created.
559
- * @param options.seed - Optional seed data to apply to the container.
639
+ * @param options.container - External container instance to provide.
640
+ * @param options.options - Managed container creation options.
560
641
  */
561
- function IocProviderController(host, _a) {
562
- var _b = _a === void 0 ? {} : _a,
563
- container = _b.container,
564
- seed = _b.seed;
642
+ function ContainerProvider(host, options) {
565
643
  var _this = this;
566
- this.host = host;
567
- this.revision = 1;
568
- this.host.addController(this);
569
- this.container = container !== null && container !== void 0 ? container : core.createContainer();
570
- this.seed = seed;
571
- this.provider = new context.ContextProvider(host, {
572
- context: IocContextObject,
573
- initialValue: {
574
- container: this.container,
575
- revision: this.revision,
576
- nextRevision: function () {
577
- return _this.nextRevision();
644
+ if (!options.container && !options.options) {
645
+ throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
646
+ } else if (options.container && options.options) {
647
+ throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
648
+ }
649
+ _this = _super.call(this, host, {
650
+ context: ContainerContext,
651
+ initialValue: options.container ? options.container : core.createContainer(tslib.__assign(tslib.__assign({}, options.options), {
652
+ activate: []
653
+ }))
654
+ }) || this;
655
+ _this.destroyed = false;
656
+ _this.options = options.options;
657
+ return _this;
658
+ }
659
+ ContainerProvider.prototype.hostConnected = function () {
660
+ var _a;
661
+ if (this.options) {
662
+ if (this.destroyed) {
663
+ this.value = core.createContainer(this.options);
664
+ this.destroyed = false;
665
+ } else {
666
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.activate) {
667
+ for (var _i = 0, _b = this.options.activate; _i < _b.length; _i++) {
668
+ var entry = _b[_i];
669
+ this.value.get(entry);
670
+ }
578
671
  }
579
672
  }
580
- });
581
- }
582
- Object.defineProperty(IocProviderController.prototype, "value", {
583
- /**
584
- * @returns Current {@link IocContext} value served to child consumers.
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);
595
673
  }
674
+ _super.prototype.hostConnected.call(this);
596
675
  };
597
- IocProviderController.prototype.hostDisconnected = function () {};
598
- IocProviderController.prototype.nextRevision = function () {
599
- var _this = this;
600
- this.revision += 1;
601
- this.provider.setValue({
602
- container: this.container,
603
- revision: this.revision,
604
- nextRevision: function () {
605
- return _this.nextRevision();
676
+ ContainerProvider.prototype.hostDisconnected = function () {
677
+ if (this.options) {
678
+ this.value.unbindAll();
679
+ this.destroyed = true;
680
+ }
681
+ };
682
+ return ContainerProvider;
683
+ }(context.ContextProvider);
684
+
685
+ /**
686
+ * Provider that exposes a managed child container for the host element's lifetime.
687
+ *
688
+ * @remarks
689
+ * The provider always owns a child container derived from the nearest parent
690
+ * {@link ContainerContext}. When connected, it creates a child container using
691
+ * the latest parent context, provides it to descendants, destroys it when the
692
+ * host disconnects, and replaces it whenever the parent container changes.
693
+ *
694
+ * @group Provision
695
+ *
696
+ * @example
697
+ * ```typescript
698
+ * class MyComponent extends LitElement {
699
+ * private container = new SubContainerProvider(this, {
700
+ * options: {
701
+ * entries: [AuthService, UserService],
702
+ * activate: [AuthService],
703
+ * seeds: [[AuthService, { role: "admin" }]],
704
+ * },
705
+ * });
706
+ * }
707
+ * ```
708
+ */
709
+ var SubContainerProvider = /** @class */function (_super) {
710
+ tslib.__extends(SubContainerProvider, _super);
711
+ /**
712
+ * @param host - The host element.
713
+ * @param options - Provisioning options, including child entries, eager activations, and seeds.
714
+ */
715
+ function SubContainerProvider(host, options) {
716
+ var _this = _super.call(this, host, {
717
+ context: ContainerContext
718
+ }) || this;
719
+ _this.parent = null;
720
+ _this.destroyed = true;
721
+ _this.options = options.options;
722
+ _this.consumer = new context.ContextConsumer(host, {
723
+ context: ContainerContext,
724
+ subscribe: true,
725
+ callback: function (context) {
726
+ var previousParent = _this.parent;
727
+ _this.parent = context;
728
+ if (host.isConnected) {
729
+ if (_this.destroyed || !_this.value || previousParent !== context) {
730
+ _this.destroyContainer();
731
+ _this.createContainer();
732
+ }
733
+ }
606
734
  }
607
735
  });
608
- return this.revision;
736
+ return _this;
737
+ }
738
+ SubContainerProvider.prototype.hostConnected = function () {
739
+ if (this.parent && (this.destroyed || !this.value)) {
740
+ this.destroyContainer();
741
+ this.createContainer();
742
+ }
743
+ _super.prototype.hostConnected.call(this);
609
744
  };
610
- return IocProviderController;
611
- }();
745
+ SubContainerProvider.prototype.hostDisconnected = function () {
746
+ this.destroyContainer();
747
+ };
748
+ /**
749
+ * Replaces the currently provided child container with a new one derived
750
+ * from the latest parent context.
751
+ */
752
+ SubContainerProvider.prototype.createContainer = function () {
753
+ var container = core.createContainer(tslib.__assign(tslib.__assign({}, this.options), {
754
+ parent: this.parent
755
+ }));
756
+ this.destroyed = false;
757
+ this.value = container;
758
+ };
759
+ /**
760
+ * Destroys the currently provided child container.
761
+ */
762
+ SubContainerProvider.prototype.destroyContainer = function () {
763
+ if (this.value && !this.destroyed) {
764
+ this.value.unbindAll();
765
+ this.destroyed = true;
766
+ }
767
+ };
768
+ return SubContainerProvider;
769
+ }(context.ContextProvider);
612
770
 
613
771
  /**
614
772
  * Decorator that provides an IoC container to child components.
615
773
  *
616
774
  * @remarks
617
- * The container is provided via Lit context. It is created (or used from options) when the host connects.
775
+ * The container is provided via Lit context.
776
+ *
777
+ * - Pass `container` to expose an external container without taking
778
+ * ownership.
779
+ * - Pass `options` to create a managed container during construction,
780
+ * activate configured entries on connect, destroy it on disconnect, and
781
+ * recreate it on reconnect.
618
782
  *
619
783
  * @group Provision
620
784
  *
621
785
  * @param options - Provisioning options.
622
- * @param options.container - Optional existing container to use, if not provided, a new one will be created.
623
- * @param options.seed - Optional seed data to apply to the container.
624
- * @returns An instance of {@link IocProviderDecorator}.
786
+ * @param options.container - External container instance to provide.
787
+ * @param options.options - Managed container creation options.
788
+ * @returns An instance of {@link ContainerProviderDecorator}.
789
+ *
790
+ * @example
791
+ * ```typescript
792
+ * class MyRootElement extends LitElement {
793
+ * @containerProvide({
794
+ * options: {
795
+ * seed: { someData: "value" },
796
+ * entries: [LoggerService],
797
+ * },
798
+ * })
799
+ * private containerProvider!: ContainerProvider;
800
+ * }
801
+ * ```
625
802
  *
626
803
  * @example
627
804
  * ```typescript
628
805
  * class MyRootElement extends LitElement {
629
- * @iocProvide({ seed: { someData: "value" } })
630
- * private ioc!: IocProviderController;
806
+ * @containerProvide({ container: container })
807
+ * private containerProvider!: ContainerProvider;
631
808
  * }
632
809
  * ```
633
810
  */
634
- function iocProvide(_a) {
635
- var _b = _a === void 0 ? {} : _a,
636
- container = _b.container,
637
- seed = _b.seed;
811
+ function containerProvide(options) {
638
812
  return function (protoOrTarget, nameOrContext) {
639
813
  if (typeof nameOrContext === "object") {
640
814
  // Standard decorators:
641
815
  nameOrContext.addInitializer(function () {
642
- protoOrTarget.set.call(this, new IocProviderController(this, {
643
- container: container,
644
- seed: seed
645
- }));
816
+ protoOrTarget.set.call(this, new ContainerProvider(this, options));
646
817
  });
647
818
  } else {
648
819
  var controller_1;
649
820
  protoOrTarget.constructor.addInitializer(function (element) {
650
- controller_1 = new IocProviderController(element, {
651
- container: container,
652
- seed: seed
653
- });
821
+ controller_1 = new ContainerProvider(element, options);
654
822
  });
655
823
  return {
656
824
  get: function () {
@@ -664,158 +832,49 @@ function iocProvide(_a) {
664
832
  };
665
833
  }
666
834
 
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
835
  /**
786
- * Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
836
+ * Decorator that provides a managed child container derived from the nearest
837
+ * parent container context.
787
838
  *
788
839
  * @remarks
789
- * Entries are bound when the host connects and unbound when it disconnects.
840
+ * The child container is created from the current parent context when the host
841
+ * connects, destroyed when it disconnects, and recreated when the parent
842
+ * container changes.
790
843
  *
791
844
  * @group Provision
792
845
  *
793
846
  * @param options - Provisioning options.
794
- * @returns An instance of {@link InjectablesProviderDecorator}.
847
+ * @param options.options - Child-container creation options.
848
+ * @returns An instance of {@link SubContainerProviderDecorator}.
795
849
  *
796
850
  * @example
797
851
  * ```typescript
798
852
  * class MyComponent extends LitElement {
799
- * @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
800
- * public controller!: InjectablesProviderController<MyComponent>;
853
+ * @subContainerProvide({
854
+ * options: {
855
+ * entries: [AuthService, UserService],
856
+ * activate: [AuthService],
857
+ * },
858
+ * })
859
+ * public containerProvider!: SubContainerProvider<MyComponent>;
801
860
  * }
802
861
  * ```
803
862
  */
804
- function injectablesProvide(options) {
863
+ function subContainerProvide(options) {
805
864
  return function (protoOrTarget, nameOrContext) {
806
865
  if (typeof nameOrContext === "object") {
807
866
  // Standard decorators:
808
867
  nameOrContext.addInitializer(function () {
809
- protoOrTarget.set.call(this, new InjectablesProviderController(this, options));
868
+ protoOrTarget.set.call(this, new SubContainerProvider(this, options));
810
869
  });
811
870
  } else {
812
- var controller_1;
871
+ var provider_1;
813
872
  protoOrTarget.constructor.addInitializer(function (element) {
814
- controller_1 = new InjectablesProviderController(element, options);
873
+ provider_1 = new SubContainerProvider(element, options);
815
874
  });
816
875
  return {
817
876
  get: function () {
818
- return controller_1;
877
+ return provider_1;
819
878
  },
820
879
  set: function () {},
821
880
  configurable: true,
@@ -826,67 +885,93 @@ function injectablesProvide(options) {
826
885
  }
827
886
 
828
887
  /**
829
- * Hook that binds injectables to the nearest IoC container for the host element's lifetime.
888
+ * Hook that provides a container to the host element and its children.
889
+ *
890
+ * @remarks
891
+ * Pass `container` to expose an external `Container` without taking
892
+ * ownership. Pass `options` to create a managed container during
893
+ * construction, activate configured entries on connect, destroy it on
894
+ * disconnect, and recreate it on reconnect.
830
895
  *
831
896
  * @group Provision
832
897
  *
833
898
  * @param host - The host element.
834
899
  * @param options - Provisioning options.
835
- * @returns An instance of {@link InjectablesProviderController}.
900
+ * @param options.container - External container instance to provide.
901
+ * @param options.options - Managed container creation options.
902
+ * @returns An instance of {@link ContainerProvider}.
836
903
  *
837
904
  * @example
838
905
  * ```typescript
839
- * class MyComponent extends LitElement {
840
- * private services = useInjectablesProvider(this, {
841
- * entries: [AuthService, UserService],
842
- * activate: [AuthService],
906
+ * class MyRootElement extends LitElement {
907
+ * private containerProvider: ContainerProvider = useContainerProvision(this, {
908
+ * options: {
909
+ * entries: [LoggerService],
910
+ * activate: [LoggerService],
911
+ * },
843
912
  * });
844
913
  * }
845
914
  * ```
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * class MyRootElement extends LitElement {
919
+ * private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
920
+ * }
921
+ * ```
846
922
  */
847
- function useInjectablesProvider(host, options) {
848
- return new InjectablesProviderController(host, options);
923
+ function useContainerProvision(host, options) {
924
+ return new ContainerProvider(host, options);
849
925
  }
850
926
 
851
927
  /**
852
- * Hook that provides an IoC container to the host element and its children.
928
+ * Hook that provides a managed child container for the host element's lifetime.
929
+ *
930
+ * @remarks
931
+ * The child container is derived from the current parent
932
+ * {@link ContainerContext}, recreated when that parent context changes, and
933
+ * destroyed when the host disconnects.
853
934
  *
854
935
  * @group Provision
855
936
  *
856
937
  * @param host - The host element.
857
938
  * @param options - Provisioning options.
858
- * @returns An instance of {@link IocProviderController}.
939
+ * @param options.options - Child-container creation options.
940
+ * @returns An instance of {@link SubContainerProvider}.
859
941
  *
860
942
  * @example
861
943
  * ```typescript
862
- * class MyRootElement extends LitElement {
863
- * private ioc = useIocProvision(this, { seed: { initialData: "..." } });
944
+ * class MyComponent extends LitElement {
945
+ * private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
946
+ * options: {
947
+ * entries: [AuthService, UserService],
948
+ * },
949
+ * });
864
950
  * }
865
951
  * ```
866
952
  */
867
- function useIocProvision(host, options) {
868
- if (options === void 0) {
869
- options = {};
870
- }
871
- return new IocProviderController(host, options);
953
+ function useSubContainerProvider(host, options) {
954
+ return new SubContainerProvider(host, options);
872
955
  }
873
956
 
874
- exports.InjectablesProviderController = InjectablesProviderController;
875
- exports.IocContextObject = IocContextObject;
876
- exports.IocProviderController = IocProviderController;
957
+ exports.ContainerContext = ContainerContext;
958
+ exports.ContainerProvider = ContainerProvider;
877
959
  exports.OnCommandController = OnCommandController;
878
960
  exports.OnEventController = OnEventController;
879
961
  exports.OnQueryController = OnQueryController;
880
- exports.injectablesProvide = injectablesProvide;
962
+ exports.SubContainerProvider = SubContainerProvider;
963
+ exports.containerProvide = containerProvide;
881
964
  exports.injection = injection;
882
- exports.iocProvide = iocProvide;
883
965
  exports.onCommand = onCommand;
884
966
  exports.onEvent = onEvent;
885
967
  exports.onQuery = onQuery;
886
- exports.useInjectablesProvider = useInjectablesProvider;
968
+ exports.subContainerProvide = subContainerProvide;
969
+ exports.useContainer = useContainer;
970
+ exports.useContainerProvision = useContainerProvision;
887
971
  exports.useInjection = useInjection;
888
- exports.useIocProvision = useIocProvision;
889
972
  exports.useOnCommand = useOnCommand;
890
973
  exports.useOnEvents = useOnEvents;
891
974
  exports.useOnQuery = useOnQuery;
975
+ exports.useScope = useScope;
976
+ exports.useSubContainerProvider = useSubContainerProvider;
892
977
  //# sourceMappingURL=index.js.map