@wirestate/lit 0.7.0-experimental.1 → 0.7.0-experimental.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +49 -31
  3. package/cjs/development/index.js +420 -362
  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 +19 -22
  8. package/esm/development/commands/on-command-controller.js.map +1 -1
  9. package/esm/development/commands/on-command.js +4 -9
  10. package/esm/development/commands/on-command.js.map +1 -1
  11. package/esm/development/commands/use-on-command.js +4 -3
  12. package/esm/development/commands/use-on-command.js.map +1 -1
  13. package/esm/development/consumption/injection.js +14 -13
  14. package/esm/development/consumption/injection.js.map +1 -1
  15. package/esm/development/consumption/use-container.js +40 -0
  16. package/esm/development/consumption/use-container.js.map +1 -0
  17. package/esm/development/consumption/use-injection.js +12 -10
  18. package/esm/development/consumption/use-injection.js.map +1 -1
  19. package/esm/development/consumption/use-scope.js +44 -0
  20. package/esm/development/consumption/use-scope.js.map +1 -0
  21. package/esm/development/context/container-context.js +17 -0
  22. package/esm/development/context/container-context.js.map +1 -0
  23. package/esm/development/error/error-code.js +1 -1
  24. package/esm/development/error/error-code.js.map +1 -1
  25. package/esm/development/events/on-event-controller.js +22 -26
  26. package/esm/development/events/on-event-controller.js.map +1 -1
  27. package/esm/development/events/on-event.js +5 -11
  28. package/esm/development/events/on-event.js.map +1 -1
  29. package/esm/development/events/use-on-events.js +5 -5
  30. package/esm/development/events/use-on-events.js.map +1 -1
  31. package/esm/development/index.js +9 -7
  32. package/esm/development/index.js.map +1 -1
  33. package/esm/development/provision/container-provide.js +68 -0
  34. package/esm/development/provision/container-provide.js.map +1 -0
  35. package/esm/development/provision/container-provider.js +68 -0
  36. package/esm/development/provision/container-provider.js.map +1 -0
  37. package/esm/development/provision/sub-container-provide.js +56 -0
  38. package/esm/development/provision/sub-container-provide.js.map +1 -0
  39. package/esm/development/provision/sub-container-provider.js +90 -0
  40. package/esm/development/provision/sub-container-provider.js.map +1 -0
  41. package/esm/development/provision/use-container-provision.js +44 -0
  42. package/esm/development/provision/use-container-provision.js.map +1 -0
  43. package/esm/development/provision/use-sub-container-provider.js +34 -0
  44. package/esm/development/provision/use-sub-container-provider.js.map +1 -0
  45. package/esm/development/queries/on-query-controller.js +19 -22
  46. package/esm/development/queries/on-query-controller.js.map +1 -1
  47. package/esm/development/queries/on-query.js +4 -9
  48. package/esm/development/queries/on-query.js.map +1 -1
  49. package/esm/development/queries/use-on-query.js +4 -3
  50. package/esm/development/queries/use-on-query.js.map +1 -1
  51. package/esm/production/commands/on-command-controller.js +1 -1
  52. package/esm/production/commands/on-command-controller.js.map +1 -1
  53. package/esm/production/commands/on-command.js +1 -1
  54. package/esm/production/commands/on-command.js.map +1 -1
  55. package/esm/production/commands/use-on-command.js +1 -1
  56. package/esm/production/commands/use-on-command.js.map +1 -1
  57. package/esm/production/consumption/injection.js +1 -1
  58. package/esm/production/consumption/injection.js.map +1 -1
  59. package/esm/production/consumption/use-container.js +1 -0
  60. package/esm/production/consumption/use-container.js.map +1 -0
  61. package/esm/production/consumption/use-injection.js +1 -1
  62. package/esm/production/consumption/use-injection.js.map +1 -1
  63. package/esm/production/consumption/use-scope.js +1 -0
  64. package/esm/production/consumption/use-scope.js.map +1 -0
  65. package/esm/production/context/container-context.js +1 -0
  66. package/esm/production/context/container-context.js.map +1 -0
  67. package/esm/production/error/error-code.js +1 -1
  68. package/esm/production/error/error-code.js.map +1 -1
  69. package/esm/production/events/on-event-controller.js +1 -1
  70. package/esm/production/events/on-event-controller.js.map +1 -1
  71. package/esm/production/events/on-event.js +1 -1
  72. package/esm/production/events/on-event.js.map +1 -1
  73. package/esm/production/events/use-on-events.js +1 -1
  74. package/esm/production/events/use-on-events.js.map +1 -1
  75. package/esm/production/index.js +1 -1
  76. package/esm/production/provision/container-provide.js +1 -0
  77. package/esm/production/provision/container-provide.js.map +1 -0
  78. package/esm/production/provision/container-provider.js +1 -0
  79. package/esm/production/provision/container-provider.js.map +1 -0
  80. package/esm/production/provision/sub-container-provide.js +1 -0
  81. package/esm/production/provision/sub-container-provide.js.map +1 -0
  82. package/esm/production/provision/sub-container-provider.js +1 -0
  83. package/esm/production/provision/sub-container-provider.js.map +1 -0
  84. package/esm/production/provision/use-container-provision.js +1 -0
  85. package/esm/production/provision/use-container-provision.js.map +1 -0
  86. package/esm/production/provision/use-sub-container-provider.js +1 -0
  87. package/esm/production/provision/use-sub-container-provider.js.map +1 -0
  88. package/esm/production/queries/on-query-controller.js +1 -1
  89. package/esm/production/queries/on-query-controller.js.map +1 -1
  90. package/esm/production/queries/on-query.js +1 -1
  91. package/esm/production/queries/on-query.js.map +1 -1
  92. package/esm/production/queries/use-on-query.js +1 -1
  93. package/esm/production/queries/use-on-query.js.map +1 -1
  94. package/index.d.ts +271 -176
  95. package/package.json +2 -2
  96. package/esm/development/context/ioc-context.js +0 -17
  97. package/esm/development/context/ioc-context.js.map +0 -1
  98. package/esm/development/provision/injectables-provide.js +0 -47
  99. package/esm/development/provision/injectables-provide.js.map +0 -1
  100. package/esm/development/provision/injectables-provider-controller.js +0 -123
  101. package/esm/development/provision/injectables-provider-controller.js.map +0 -1
  102. package/esm/development/provision/ioc-provide.js +0 -58
  103. package/esm/development/provision/ioc-provide.js.map +0 -1
  104. package/esm/development/provision/ioc-provider-controller.js +0 -75
  105. package/esm/development/provision/ioc-provider-controller.js.map +0 -1
  106. package/esm/development/provision/use-injectables-provider.js +0 -27
  107. package/esm/development/provision/use-injectables-provider.js.map +0 -1
  108. package/esm/development/provision/use-ioc-provision.js +0 -27
  109. package/esm/development/provision/use-ioc-provision.js.map +0 -1
  110. package/esm/production/context/ioc-context.js +0 -1
  111. package/esm/production/context/ioc-context.js.map +0 -1
  112. package/esm/production/provision/injectables-provide.js +0 -1
  113. package/esm/production/provision/injectables-provide.js.map +0 -1
  114. package/esm/production/provision/injectables-provider-controller.js +0 -1
  115. package/esm/production/provision/injectables-provider-controller.js.map +0 -1
  116. package/esm/production/provision/ioc-provide.js +0 -1
  117. package/esm/production/provision/ioc-provide.js.map +0 -1
  118. package/esm/production/provision/ioc-provider-controller.js +0 -1
  119. package/esm/production/provision/ioc-provider-controller.js.map +0 -1
  120. package/esm/production/provision/use-injectables-provider.js +0 -1
  121. package/esm/production/provision/use-injectables-provider.js.map +0 -1
  122. package/esm/production/provision/use-ioc-provision.js +0 -1
  123. package/esm/production/provision/use-ioc-provision.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.7.0
1
+ ## Unreleased
2
2
 
3
3
  - Add `useScope` in `@wirestate/react`
4
4
  - New lit elements modules - `@wirestate/lit` and `@wirestate/lit-signals`
@@ -10,13 +10,19 @@
10
10
  - Export more alias / methods from `@wirestate/react-mobx`
11
11
  - Export missing methods typing for `@wirestate/core`
12
12
  - Extensive JSDoc coverage for wirestate packages
13
- - `createIocContainer`: Added ability to instantly provide and activate entries, targeted seeds
13
+ - `createIocContainer`: Removed in favor of `createContainer`
14
+ - `createContainer`: Added ability to instantly provide and activate entries, targeted seeds
14
15
  - `createInjectablesProvider`: Removed.
15
16
  - `IocProvider`: Removed
16
17
  - `useRootContainer`: Added separate hook for store management in React tree
17
18
  - `ContainerProvider`: Simpler provider for containers.
18
19
  - `SubContainerProvider`: Added component solving problems of removed `createInjectablesProvider`
19
20
  - `ContainerActivator`: Added separate activation component
21
+ - Replace IoC-context provision APIs with `ContainerContext`, `containerProvide`, `ContainerProvider`, and `useContainerProvision`
22
+ - Replace injectables-provider APIs with `subContainerProvide`, `SubContainerProvider`, and `useSubContainerProvider`
23
+ - Provide plain `Container` values through Lit context instead of wrapper objects
24
+ - Recreate managed child containers when the parent container context changes
25
+ - Add `useContainer` and `useScope` consumers in `@wirestate/lit`
20
26
 
21
27
  ## 0.6.3
22
28
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/v/@wirestate/lit.svg?style=flat-square)](https://www.npmjs.com/package/@wirestate/lit)
4
4
  [![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/Neloreck/wirestate/blob/master/LICENSE)
5
5
 
6
- Lit elements integration for wirestate. Provides dependency injection and messaging for Lit components.
6
+ Lit elements integration for wirestate. Provides container provisioning, dependency injection, and messaging for Lit components.
7
7
 
8
8
  ## Installation
9
9
 
@@ -18,25 +18,31 @@ npm install @wirestate/core @wirestate/lit lit reflect-metadata
18
18
  - **Events**: Subscribe to events from the global event bus using `@onEvent` or `useOnEvents`.
19
19
  - **Commands**: Register command handlers using `@onCommand` or `useOnCommand`.
20
20
  - **Queries**: Register query handlers using `@onQuery` or `useOnQuery`.
21
- - **Container Provisioning**: Provide and manage IoC containers within the Lit component tree using `@iocProvide` or `useIocProvision`.
22
- - **Service Binding**: Dynamically bind services to the container using `@injectablesProvide`, `useInjectablesProvider`, or `InjectablesProviderController`.
21
+ - **Container Provisioning**: Provide and manage containers within the Lit component tree using `@containerProvide` or `useContainerProvision`.
22
+ - **Sub-containers**: Create managed child containers derived from the parent context using `@subContainerProvide`, `useSubContainerProvider`, or `SubContainerProvider`.
23
23
  - **Test Utilities**: Simplified setup for unit testing components with IoC dependencies.
24
24
 
25
25
  ## Provisioning
26
26
 
27
- ### `@iocProvide(options?)` / `useIocProvision(host, options?)`
27
+ ### `@containerProvide(options)` / `useContainerProvision(host, options)`
28
28
 
29
- Provides an IoC container to the component tree. It uses Lit Context to propagate the container to child elements.
29
+ Provides a container to the component tree. It uses Lit Context to propagate the container to child elements.
30
+
31
+ Pass `container` to expose an existing container, or pass `options` to create and manage one for the host lifecycle.
30
32
 
31
33
  ```typescript
32
34
  import { LitElement, html } from "lit";
33
35
  import { customElement } from "lit/decorators.js";
34
- import { iocProvide, IocProviderController } from "@wirestate/lit";
36
+ import { containerProvide, ContainerProvider } from "@wirestate/lit";
35
37
 
36
38
  @customElement("my-app")
37
39
  class MyApp extends LitElement {
38
- @iocProvide()
39
- private ioc!: IocProviderController;
40
+ @containerProvide({
41
+ options: {
42
+ seed: { someData: "value" },
43
+ },
44
+ })
45
+ private containerProvider!: ContainerProvider;
40
46
 
41
47
  render() {
42
48
  return html`<my-component></my-component>`;
@@ -44,23 +50,28 @@ class MyApp extends LitElement {
44
50
  }
45
51
  ```
46
52
 
47
- ### `@injectablesProvide(options)` / `useInjectablesProvider(host, options)`
53
+ ### `@subContainerProvide(options)` / `useSubContainerProvider(host, options)`
48
54
 
49
- Binds a set of injectables to the nearest IoC container for the host element's lifetime. Entries are bound when the host connects and unbound when it disconnects.
55
+ Creates a managed child container derived from the nearest parent container for the host element's lifetime. The child container is recreated when the parent container changes and destroyed when the host disconnects.
50
56
 
51
57
  Using the decorator (accessor):
52
58
 
53
59
  ```typescript
54
60
  import { LitElement } from "lit";
55
61
  import { customElement } from "lit/decorators.js";
56
- import { injectablesProvide, InjectablesProviderController } from "@wirestate/lit";
62
+ import { subContainerProvide, SubContainerProvider } from "@wirestate/lit";
57
63
 
58
64
  import { AuthService, UserService } from "./services";
59
65
 
60
66
  @customElement("my-app")
61
67
  class MyApp extends LitElement {
62
- @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
63
- public services!: InjectablesProviderController<MyApp>;
68
+ @subContainerProvide({
69
+ options: {
70
+ entries: [AuthService, UserService],
71
+ activate: [AuthService],
72
+ },
73
+ })
74
+ public containerProvider!: SubContainerProvider;
64
75
  }
65
76
  ```
66
77
 
@@ -68,45 +79,52 @@ Using the hook:
68
79
 
69
80
  ```typescript
70
81
  import { LitElement } from "lit";
71
- import { useInjectablesProvider } from "@wirestate/lit";
82
+ import { useSubContainerProvider } from "@wirestate/lit";
72
83
 
73
84
  import { AuthService, UserService } from "./services";
74
85
 
75
86
  class MyApp extends LitElement {
76
- private services = useInjectablesProvider(this, {
77
- entries: [AuthService, UserService],
78
- activate: [AuthService],
87
+ private container = useSubContainerProvider(this, {
88
+ options: {
89
+ entries: [AuthService, UserService],
90
+ activate: [AuthService],
91
+ },
79
92
  });
80
93
  }
81
94
  ```
82
95
 
83
- Using the controller directly:
96
+ Using the provider directly:
84
97
 
85
98
  ```typescript
86
99
  import { LitElement } from "lit";
87
- import { InjectablesProviderController } from "@wirestate/lit";
100
+ import { SubContainerProvider } from "@wirestate/lit";
88
101
 
89
102
  import { AuthService, UserService } from "./services";
90
103
 
91
104
  class MyApp extends LitElement {
92
- private services = new InjectablesProviderController(this, {
93
- entries: [AuthService, UserService],
94
- activate: [AuthService],
105
+ private containerProvider: SubContainerProvider = new SubContainerProvider(this, {
106
+ options: {
107
+ entries: [AuthService, UserService],
108
+ activate: [AuthService],
109
+ },
95
110
  });
96
111
  }
97
112
  ```
98
113
 
99
- To bind into a specific container instead of the nearest provider context, pass the `into` option:
114
+ To seed the child container during creation, pass `seeds` inside `options`:
100
115
 
101
116
  ```typescript
102
117
  import { LitElement } from "lit";
103
- import { useInjectablesProvider } from "@wirestate/lit";
118
+ import { useSubContainerProvider } from "@wirestate/lit";
104
119
 
105
120
  import { AuthService, UserService } from "./services";
106
121
 
107
122
  class MyApp extends LitElement {
108
- private services = useInjectablesProvider(this, {
109
- entries: [AuthService, UserService],
123
+ private provider: SubContainerProvider = useSubContainerProvider(this, {
124
+ options: {
125
+ entries: [AuthService, UserService],
126
+ seeds: [[AuthService, { role: "admin" }]],
127
+ },
110
128
  });
111
129
  }
112
130
  ```
@@ -115,7 +133,7 @@ class MyApp extends LitElement {
115
133
 
116
134
  ### `@injection(optionsOrId)` / `useInjection(host, optionsOrId)`
117
135
 
118
- Injects a service from the nearest IoC container. Supports both options object and direct service identifier.
136
+ Injects a service from the nearest parent container. Supports both options object and direct service identifier.
119
137
 
120
138
  ```typescript
121
139
  import { LitElement, html } from "lit";
@@ -140,7 +158,7 @@ class MyComponent extends LitElement {
140
158
  }
141
159
  ```
142
160
 
143
- Using the controller:
161
+ Using the hook:
144
162
 
145
163
  ```typescript
146
164
  import { LitElement, html } from "lit";
@@ -165,7 +183,7 @@ class MyComponent extends LitElement {
165
183
 
166
184
  ### Events
167
185
 
168
- Subscribe to events from the event bus using `@onEvent` decorator or `useOnEvents` controller.
186
+ Subscribe to events from the event bus using `@onEvent` decorator or `useOnEvents` controller. Handlers follow the active container context when the nearest container changes.
169
187
 
170
188
  ```typescript
171
189
  import { LitElement } from "lit";
@@ -196,7 +214,7 @@ class MyListener extends LitElement {
196
214
 
197
215
  ### Commands
198
216
 
199
- Register a handler for a specific command type.
217
+ Register a handler for a specific command type. Handlers follow the active container context when the nearest container changes.
200
218
 
201
219
  ```typescript
202
220
  import { LitElement } from "lit";
@@ -212,7 +230,7 @@ class MyCommander extends LitElement {
212
230
 
213
231
  ### Queries
214
232
 
215
- Register a handler for a specific query type.
233
+ Register a handler for a specific query type. Handlers follow the active container context when the nearest container changes.
216
234
 
217
235
  ```typescript
218
236
  import { LitElement } from "lit";