@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
package/index.d.ts CHANGED
@@ -1,13 +1,7 @@
1
1
  import { ReactiveElement, ReactiveControllerHost, ReactiveController } from '@lit/reactive-element';
2
- import { ServiceIdentifier, CommandType, CommandHandler, Event, EventType, EventHandler, QueryType, QueryHandler, Container, Newable, InjectableDescriptor, SeedEntries } from '@wirestate/core';
2
+ import { ServiceIdentifier, Container as Container$1, WireScope, CommandType, CommandHandler, Event, EventType, EventHandler, QueryType, QueryHandler, CreateContainerOptions, Newable, InjectableDescriptor, SeedEntries } from '@wirestate/core';
3
3
  import { ContextProvider, ContextConsumer } from '@lit/context';
4
4
 
5
- /**
6
- * Any object with string or symbol keys.
7
- *
8
- * @group Types
9
- */
10
- type AnyObject = Record<string | symbol, any>;
11
5
  /**
12
6
  * Type that can be null.
13
7
  *
@@ -20,6 +14,12 @@ type Optional<T> = T | null;
20
14
  * @group Types
21
15
  */
22
16
  type MaybePromise<T> = T | Promise<T>;
17
+ /**
18
+ * Value that can be null or undefined.
19
+ *
20
+ * @group Types
21
+ */
22
+ type Maybe<T> = T | null | undefined;
23
23
  /**
24
24
  * Helper to extract the interface of a type.
25
25
  *
@@ -114,6 +114,41 @@ interface InjectionOptions<T> {
114
114
  */
115
115
  declare function injection<T>(optionsOrInjectionId: InjectionOptions<T> | ServiceIdentifier<T>): InjectionDecorator<T>;
116
116
 
117
+ /**
118
+ * Represents result of the {@link useContainer} hook.
119
+ *
120
+ * @group Consumption
121
+ */
122
+ interface UseContainerValue {
123
+ /**
124
+ * The active container from the nearest parent context.
125
+ */
126
+ value: Container$1;
127
+ }
128
+ /**
129
+ * Hook (consumer) to access the active container from the nearest parent context.
130
+ *
131
+ * @remarks
132
+ * The returned value updates when the nearest provided container changes.
133
+ *
134
+ * @group Consumption
135
+ *
136
+ * @param host - The host element.
137
+ * @returns An instance of {@link UseContainerValue}.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * class MyElement extends LitElement {
142
+ * private container: UseContainerValue = useContainer(this);
143
+ *
144
+ * public render() {
145
+ * return html`<div>${this.container.value.isBound(MyService)}</div>`;
146
+ * }
147
+ * }
148
+ * ```
149
+ */
150
+ declare function useContainer<E extends ReactiveControllerHost & HTMLElement>(host: E): UseContainerValue;
151
+
117
152
  /**
118
153
  * Represents options for the {@link useInjection} hook.
119
154
  *
@@ -185,6 +220,37 @@ interface UseInjectionValue<T> {
185
220
  */
186
221
  declare function useInjection<T extends object, E extends ReactiveControllerHost & HTMLElement>(host: E, optionsOrInjectionId: UseInjectionOptions<T> | ServiceIdentifier<T>): UseInjectionValue<T>;
187
222
 
223
+ /**
224
+ * Represents result of the {@link useScope} hook.
225
+ *
226
+ * @group Consumption
227
+ */
228
+ type UseScopeValue = UseInjectionValue<WireScope>;
229
+ /**
230
+ * Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
231
+ *
232
+ * @remarks
233
+ * The returned value updates when the nearest provided container changes.
234
+ *
235
+ * @group Consumption
236
+ *
237
+ * @param host - The host element.
238
+ * @returns An instance of {@link UseScopeValue}.
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * class MyElement extends LitElement {
243
+ * private scope: UseScopeValue = useScope(this);
244
+ *
245
+ * public connectedCallback(): void {
246
+ * super.connectedCallback();
247
+ * this.scope.value.emitEvent("UI_READY");
248
+ * }
249
+ * }
250
+ * ```
251
+ */
252
+ declare function useScope<E extends ReactiveControllerHost & HTMLElement>(host: E): UseScopeValue;
253
+
188
254
  /**
189
255
  * Represents interface for the {@link onCommand} decorator.
190
256
  *
@@ -512,286 +578,315 @@ interface UseOnQueryOptions<D = unknown, R = unknown> {
512
578
  declare function useOnQuery<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnQueryOptions<D, R>): OnQueryController<D, R>;
513
579
 
514
580
  /**
515
- * Interface for the IoC context value.
516
- *
517
- * @group Context
518
- */
519
- interface IocContext {
520
- /**
521
- * The IoC container instance.
522
- */
523
- readonly container: Container;
524
- /**
525
- * Revision counter for cache invalidation.
526
- */
527
- readonly revision: number;
528
- /**
529
- * Function to force a revision update.
530
- */
531
- readonly nextRevision: () => number;
532
- }
533
- /**
534
- * Lit context object for providing and consuming the IoC container.
581
+ * Lit context object for providing and consuming the container.
535
582
  *
536
583
  * @group Context
537
584
  */
538
- declare const IocContextObject: {
539
- __context__: IocContext;
585
+ declare const ContainerContext: {
586
+ __context__: Container;
540
587
  };
541
588
 
542
589
  /**
543
- * Represents options for the {@link IocProviderController}.
590
+ * Represents options for the {@link ContainerProvider}.
591
+ *
592
+ * @remarks
593
+ * Provide either an external `container` or managed creation `options`, but
594
+ * never both at the same time.
544
595
  *
545
596
  * @group Provision
546
597
  */
547
- interface IocProviderControllerOptions {
598
+ interface ContainerProviderOptions {
548
599
  /**
549
- * Optional existing container to use. If not provided, a new one will be created.
600
+ * External container instance to provide as-is.
601
+ *
602
+ * @remarks
603
+ * External containers are never activated, recreated, or disposed by this
604
+ * provider.
550
605
  */
551
- container?: Container;
606
+ readonly container?: Container$1;
552
607
  /**
553
- * Optional seed data to apply to the container.
608
+ * Managed container creation options.
609
+ *
610
+ * @remarks
611
+ * The managed container is created during provider construction without
612
+ * eager activation, activated when the host connects, disposed when it
613
+ * disconnects, and recreated on the next reconnect.
554
614
  */
555
- seed?: AnyObject;
615
+ readonly options?: CreateContainerOptions;
556
616
  }
557
617
  /**
558
- * Controller that provides an IoC container context to the host element and its children.
618
+ * Provider that exposes an IoC container context to the host element and its children.
559
619
  *
560
620
  * @remarks
561
- * It manages the lifecycle of the container and handles revision updates to notify consumers.
562
- * The container is created (or used from options) when the controller is instantiated.
563
- * Seed data is applied when the host connects.
621
+ * The provider supports two modes:
622
+ *
623
+ * - External mode: `container` is an existing {@link Container}. The
624
+ * provider passes it through context and does not alter its lifecycle.
625
+ * - Managed mode: `options` is {@link CreateContainerOptions}. The provider
626
+ * creates a container during construction without eager activation,
627
+ * activates configured entries when the host connects, disposes the
628
+ * container when the host disconnects, and recreates it on reconnect.
564
629
  *
565
630
  * @group Provision
566
631
  */
567
- declare class IocProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
568
- private readonly host;
569
- protected readonly provider: ContextProvider<typeof IocContextObject>;
570
- protected readonly seed?: AnyObject;
571
- protected revision: number;
572
- /**
573
- * The managed Inversify IoC container.
574
- */
575
- container: Container;
576
- /**
577
- * @returns Current {@link IocContext} value served to child consumers.
578
- */
579
- get value(): IocContext;
632
+ declare class ContainerProvider<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> extends ContextProvider<typeof ContainerContext, E> implements ReactiveController {
633
+ protected readonly options: Maybe<CreateContainerOptions>;
634
+ protected destroyed: boolean;
580
635
  /**
581
636
  * @param host - The host element.
582
637
  * @param options - Provisioning options.
583
- * @param options.container - Optional existing container to use. If not provided, a new one will be created.
584
- * @param options.seed - Optional seed data to apply to the container.
638
+ * @param options.container - External container instance to provide.
639
+ * @param options.options - Managed container creation options.
585
640
  */
586
- constructor(host: E, { container, seed }?: IocProviderControllerOptions);
641
+ constructor(host: E, options: ContainerProviderOptions);
587
642
  hostConnected(): void;
588
643
  hostDisconnected(): void;
589
- nextRevision(): number;
590
644
  }
591
645
 
592
646
  /**
593
- * Represents interface for the {@link iocProvide} decorator.
594
- *
595
- * @remarks
596
- * Supports both TC39 and legacy experimental decorators.
647
+ * Represents options for the {@link SubContainerProvider}.
597
648
  *
598
649
  * @group Provision
599
650
  */
600
- interface IocProviderDecorator<E extends ReactiveElement = ReactiveElement> {
601
- <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends IocProviderController<E>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
602
- <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, IocProviderController<E>>;
651
+ interface SubContainerProviderOptions {
652
+ /**
653
+ * Managed child-container creation options.
654
+ *
655
+ * @remarks
656
+ * The child container is created from the current parent context when the
657
+ * host connects, destroyed when the host disconnects, and recreated when the
658
+ * parent context changes or the host reconnects.
659
+ */
660
+ readonly options: {
661
+ /**
662
+ * List of service entries to bind to the container.
663
+ */
664
+ readonly entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
665
+ /**
666
+ * List of service identifiers to activate (get from container) immediately after binding.
667
+ */
668
+ readonly activate?: ReadonlyArray<ServiceIdentifier>;
669
+ /**
670
+ * Seed data to apply to the container before binding.
671
+ * Applied before entries are bound so that `@Inject(SEEDS_TOKEN)` works during activation.
672
+ */
673
+ readonly seeds?: SeedEntries;
674
+ };
603
675
  }
604
676
  /**
605
- * Decorator that provides an IoC container to child components.
677
+ * Provider that exposes a managed child container for the host element's lifetime.
606
678
  *
607
679
  * @remarks
608
- * The container is provided via Lit context. It is created (or used from options) when the host connects.
680
+ * The provider always owns a child container derived from the nearest parent
681
+ * {@link ContainerContext}. When connected, it creates a child container using
682
+ * the latest parent context, provides it to descendants, destroys it when the
683
+ * host disconnects, and replaces it whenever the parent container changes.
609
684
  *
610
685
  * @group Provision
611
686
  *
612
- * @param options - Provisioning options.
613
- * @param options.container - Optional existing container to use, if not provided, a new one will be created.
614
- * @param options.seed - Optional seed data to apply to the container.
615
- * @returns An instance of {@link IocProviderDecorator}.
616
- *
617
687
  * @example
618
688
  * ```typescript
619
- * class MyRootElement extends LitElement {
620
- * @iocProvide({ seed: { someData: "value" } })
621
- * private ioc!: IocProviderController;
689
+ * class MyComponent extends LitElement {
690
+ * private container = new SubContainerProvider(this, {
691
+ * options: {
692
+ * entries: [AuthService, UserService],
693
+ * activate: [AuthService],
694
+ * seeds: [[AuthService, { role: "admin" }]],
695
+ * },
696
+ * });
622
697
  * }
623
698
  * ```
624
699
  */
625
- declare function iocProvide<E extends ReactiveElement>({ container, seed, }?: IocProviderControllerOptions): IocProviderDecorator<E>;
626
-
627
- /**
628
- * Represents a function that returns a value of type `T`.
629
- *
630
- * @group general-types
631
- *
632
- * @template T - The return type of the function.
633
- */
634
- type Callable<T> = () => T;
635
-
636
- /**
637
- * Represents options for the {@link InjectablesProviderController}.
638
- *
639
- * @group Provision
640
- */
641
- interface InjectablesProviderControllerOptions {
642
- /**
643
- * List of service entries to bind to the container.
644
- */
645
- entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
700
+ declare class SubContainerProvider<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> extends ContextProvider<typeof ContainerContext, E> implements ReactiveController {
701
+ protected readonly consumer: ContextConsumer<typeof ContainerContext, E>;
702
+ protected readonly options: SubContainerProviderOptions["options"];
703
+ protected parent: Maybe<Container$1>;
704
+ protected destroyed: boolean;
646
705
  /**
647
- * Target IoC context to bind injectables into.
648
- * If not provided, uses the context from the nearest provider.
649
- * Accepts a static {@link IocContext} reference or a resolver function.
706
+ * @param host - The host element.
707
+ * @param options - Provisioning options, including child entries, eager activations, and seeds.
650
708
  */
651
- into?: IocContext | Callable<IocContext>;
709
+ constructor(host: E, options: SubContainerProviderOptions);
710
+ hostConnected(): void;
711
+ hostDisconnected(): void;
652
712
  /**
653
- * List of service identifiers to activate (get from container) immediately after binding.
713
+ * Replaces the currently provided child container with a new one derived
714
+ * from the latest parent context.
654
715
  */
655
- activate?: ReadonlyArray<ServiceIdentifier>;
716
+ protected createContainer(): void;
656
717
  /**
657
- * Seed data to apply to the container before binding.
658
- * Applied before entries are bound so that `@Inject(SEEDS_TOKEN)` works during activation.
718
+ * Destroys the currently provided child container.
659
719
  */
660
- seeds?: SeedEntries;
720
+ protected destroyContainer(): void;
721
+ }
722
+
723
+ /**
724
+ * Represents interface for the {@link containerProvide} decorator.
725
+ *
726
+ * @remarks
727
+ * Supports both TC39 and legacy experimental decorators.
728
+ *
729
+ * @group Provision
730
+ */
731
+ interface ContainerProviderDecorator<E extends ReactiveElement = ReactiveElement> {
732
+ <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends ContainerProvider<E>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
733
+ <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, ContainerProvider<E>>;
661
734
  }
662
735
  /**
663
- * Controller that binds injectables to an IoC container for the host element's lifetime.
736
+ * Decorator that provides an IoC container to child components.
664
737
  *
665
738
  * @remarks
666
- * Entries are bound when the host connects and unbound when it disconnects.
667
- * If no `into` context is provided, it uses the nearest {@link IocProviderController}.
668
- * Seeds are applied before entries are bound.
739
+ * The container is provided via Lit context.
740
+ *
741
+ * - Pass `container` to expose an external container without taking
742
+ * ownership.
743
+ * - Pass `options` to create a managed container during construction,
744
+ * activate configured entries on connect, destroy it on disconnect, and
745
+ * recreate it on reconnect.
669
746
  *
670
747
  * @group Provision
671
748
  *
749
+ * @param options - Provisioning options.
750
+ * @param options.container - External container instance to provide.
751
+ * @param options.options - Managed container creation options.
752
+ * @returns An instance of {@link ContainerProviderDecorator}.
753
+ *
672
754
  * @example
673
755
  * ```typescript
674
- * class MyComponent extends LitElement {
675
- * private services = new InjectablesProviderController(this, {
676
- * entries: [AuthService, UserService],
677
- * activate: [AuthService],
678
- * seeds: [[AuthService, { role: "admin" }]],
679
- * });
756
+ * class MyRootElement extends LitElement {
757
+ * @containerProvide({
758
+ * options: {
759
+ * seed: { someData: "value" },
760
+ * entries: [LoggerService],
761
+ * },
762
+ * })
763
+ * private containerProvider!: ContainerProvider;
764
+ * }
765
+ * ```
766
+ *
767
+ * @example
768
+ * ```typescript
769
+ * class MyRootElement extends LitElement {
770
+ * @containerProvide({ container: container })
771
+ * private containerProvider!: ContainerProvider;
680
772
  * }
681
773
  * ```
682
774
  */
683
- declare class InjectablesProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
684
- private readonly host;
685
- protected readonly consumer?: ContextConsumer<typeof IocContextObject, E>;
686
- private readonly entries;
687
- private readonly activate;
688
- private readonly seeds;
689
- private readonly into;
690
- /**
691
- * Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
692
- */
693
- private boundContext;
694
- /**
695
- * @param host - The host element.
696
- * @param options - Provisioning options.
697
- * @param options.entries - List of service entries to bind to the container.
698
- * @param options.into - Target IoC context; if omitted, uses the nearest provider context.
699
- * @param options.activate - List of service identifiers to activate immediately after binding.
700
- * @param options.seeds - Seed data applied before binding.
701
- */
702
- constructor(host: E, options: InjectablesProviderControllerOptions);
703
- hostConnected(): void;
704
- hostDisconnected(): void;
705
- private bind;
706
- private unbind;
707
- }
775
+ declare function containerProvide<E extends ReactiveElement>(options: ContainerProviderOptions): ContainerProviderDecorator<E>;
708
776
 
709
777
  /**
710
- * Represents type for the {@link injectablesProvide} decorator.
778
+ * Represents type for the {@link subContainerProvide} decorator.
711
779
  *
712
780
  * @remarks
713
781
  * Supports both TC39 and legacy experimental decorators.
714
782
  *
715
783
  * @group Provision
716
784
  */
717
- interface InjectablesProviderDecorator<T extends ReactiveElement = ReactiveElement> {
718
- <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends InjectablesProviderController<T>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
719
- <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, InjectablesProviderController<T>>;
785
+ interface SubContainerProviderDecorator<T extends ReactiveElement = ReactiveElement> {
786
+ <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends SubContainerProvider<T>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
787
+ <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, SubContainerProvider<T>>;
720
788
  }
721
789
  /**
722
- * Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
790
+ * Decorator that provides a managed child container derived from the nearest
791
+ * parent container context.
723
792
  *
724
793
  * @remarks
725
- * Entries are bound when the host connects and unbound when it disconnects.
794
+ * The child container is created from the current parent context when the host
795
+ * connects, destroyed when it disconnects, and recreated when the parent
796
+ * container changes.
726
797
  *
727
798
  * @group Provision
728
799
  *
729
800
  * @param options - Provisioning options.
730
- * @returns An instance of {@link InjectablesProviderDecorator}.
801
+ * @param options.options - Child-container creation options.
802
+ * @returns An instance of {@link SubContainerProviderDecorator}.
731
803
  *
732
804
  * @example
733
805
  * ```typescript
734
806
  * class MyComponent extends LitElement {
735
- * @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
736
- * public controller!: InjectablesProviderController<MyComponent>;
807
+ * @subContainerProvide({
808
+ * options: {
809
+ * entries: [AuthService, UserService],
810
+ * activate: [AuthService],
811
+ * },
812
+ * })
813
+ * public containerProvider!: SubContainerProvider<MyComponent>;
737
814
  * }
738
815
  * ```
739
816
  */
740
- declare function injectablesProvide<E extends ReactiveElement = ReactiveElement>(options: InjectablesProviderControllerOptions): InjectablesProviderDecorator<E>;
817
+ declare function subContainerProvide<E extends ReactiveElement = ReactiveElement>(options: SubContainerProviderOptions): SubContainerProviderDecorator<E>;
741
818
 
742
819
  /**
743
- * Hook that binds injectables to the nearest IoC container for the host element's lifetime.
820
+ * Represents options for the {@link useContainerProvision} hook.
821
+ *
822
+ * @group Provision
823
+ */
824
+ type UseContainerProvisionOptions = ContainerProviderOptions;
825
+ /**
826
+ * Hook that provides a container to the host element and its children.
827
+ *
828
+ * @remarks
829
+ * Pass `container` to expose an external `Container` without taking
830
+ * ownership. Pass `options` to create a managed container during
831
+ * construction, activate configured entries on connect, destroy it on
832
+ * disconnect, and recreate it on reconnect.
744
833
  *
745
834
  * @group Provision
746
835
  *
747
836
  * @param host - The host element.
748
837
  * @param options - Provisioning options.
749
- * @returns An instance of {@link InjectablesProviderController}.
838
+ * @param options.container - External container instance to provide.
839
+ * @param options.options - Managed container creation options.
840
+ * @returns An instance of {@link ContainerProvider}.
750
841
  *
751
842
  * @example
752
843
  * ```typescript
753
- * class MyComponent extends LitElement {
754
- * private services = useInjectablesProvider(this, {
755
- * entries: [AuthService, UserService],
756
- * activate: [AuthService],
844
+ * class MyRootElement extends LitElement {
845
+ * private containerProvider: ContainerProvider = useContainerProvision(this, {
846
+ * options: {
847
+ * entries: [LoggerService],
848
+ * activate: [LoggerService],
849
+ * },
757
850
  * });
758
851
  * }
759
852
  * ```
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * class MyRootElement extends LitElement {
857
+ * private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
858
+ * }
859
+ * ```
760
860
  */
761
- declare function useInjectablesProvider<E extends ReactiveControllerHost & HTMLElement>(host: E, options: InjectablesProviderControllerOptions): InjectablesProviderController<E>;
861
+ declare function useContainerProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, options: UseContainerProvisionOptions): ContainerProvider<E>;
762
862
 
763
863
  /**
764
- * Represents options for the {@link useIocProvision} hook.
864
+ * Hook that provides a managed child container for the host element's lifetime.
765
865
  *
766
- * @group Provision
767
- */
768
- interface UseIocProvisionOptions {
769
- /**
770
- * Optional existing container to use.
771
- */
772
- container?: Container;
773
- /**
774
- * Optional seed data to apply to the container.
775
- */
776
- seed?: AnyObject;
777
- }
778
- /**
779
- * Hook that provides an IoC container to the host element and its children.
866
+ * @remarks
867
+ * The child container is derived from the current parent
868
+ * {@link ContainerContext}, recreated when that parent context changes, and
869
+ * destroyed when the host disconnects.
780
870
  *
781
871
  * @group Provision
782
872
  *
783
873
  * @param host - The host element.
784
874
  * @param options - Provisioning options.
785
- * @returns An instance of {@link IocProviderController}.
875
+ * @param options.options - Child-container creation options.
876
+ * @returns An instance of {@link SubContainerProvider}.
786
877
  *
787
878
  * @example
788
879
  * ```typescript
789
- * class MyRootElement extends LitElement {
790
- * private ioc = useIocProvision(this, { seed: { initialData: "..." } });
880
+ * class MyComponent extends LitElement {
881
+ * private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
882
+ * options: {
883
+ * entries: [AuthService, UserService],
884
+ * },
885
+ * });
791
886
  * }
792
887
  * ```
793
888
  */
794
- declare function useIocProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, options?: UseIocProvisionOptions): IocProviderController<E>;
889
+ declare function useSubContainerProvider<E extends ReactiveControllerHost & HTMLElement>(host: E, options: SubContainerProviderOptions): SubContainerProvider<E>;
795
890
 
796
- export { InjectablesProviderController, IocContextObject, IocProviderController, OnCommandController, OnEventController, OnQueryController, injectablesProvide, injection, iocProvide, onCommand, onEvent, onQuery, useInjectablesProvider, useInjection, useIocProvision, useOnCommand, useOnEvents, useOnQuery };
797
- export type { InjectablesProviderControllerOptions, InjectablesProviderDecorator, InjectionDecorator, InjectionOptions, IocContext, IocProviderControllerOptions, IocProviderDecorator, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, UseInjectionOptions, UseInjectionValue, UseIocProvisionOptions, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions };
891
+ export { ContainerContext, ContainerProvider, OnCommandController, OnEventController, OnQueryController, SubContainerProvider, containerProvide, injection, onCommand, onEvent, onQuery, subContainerProvide, useContainer, useContainerProvision, useInjection, useOnCommand, useOnEvents, useOnQuery, useScope, useSubContainerProvider };
892
+ export type { ContainerProviderDecorator, ContainerProviderOptions, InjectionDecorator, InjectionOptions, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, SubContainerProviderDecorator, SubContainerProviderOptions, UseContainerProvisionOptions, UseContainerValue, UseInjectionOptions, UseInjectionValue, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions, UseScopeValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirestate/lit",
3
- "version": "0.7.0-experimental.1",
3
+ "version": "0.7.0-experimental.2",
4
4
  "description": "Lit elements integration for wirestate",
5
5
  "sideEffects": false,
6
6
  "author": "Syrotenko Igor",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "dependencies": {},
49
49
  "peerDependencies": {
50
- "@wirestate/core": ">=0.6.0",
50
+ "@wirestate/core": ">=0.7.0-experimental.1",
51
51
  "@lit/reactive-element": ">=2.0.0",
52
52
  "@lit/context": ">=1.0.0",
53
53
  "reflect-metadata": ">=0.2.0",
@@ -1,17 +0,0 @@
1
- import { createContext } from '@lit/context';
2
-
3
- /**
4
- * Unique symbol used as a key for the IoC context.
5
- *
6
- * @group Context
7
- */
8
- var IOC_CONTAINER_KEY = Symbol("ContainerContext");
9
- /**
10
- * Lit context object for providing and consuming the IoC container.
11
- *
12
- * @group Context
13
- */
14
- var IocContextObject = createContext(IOC_CONTAINER_KEY);
15
-
16
- export { IOC_CONTAINER_KEY, IocContextObject };
17
- //# sourceMappingURL=ioc-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ioc-context.js","sources":["../../../../../../../../src/wirestate-lit/context/ioc-context.ts"],"sourcesContent":[null],"names":["IOC_CONTAINER_KEY","Symbol","IocContextObject","createContext"],"mappings":";;AAGA;;;;AAIG;IACUA,iBAAiB,GAAkBC,MAAM,CAAC,kBAAkB;AAsBzE;;;;AAIG;IACUC,gBAAgB,GAAGC,aAAa,CAAaH,iBAAiB;;;;"}