@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
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
##
|
|
1
|
+
## Unreleased
|
|
2
2
|
|
|
3
3
|
- Add `useScope` in `@wirestate/react`
|
|
4
4
|
- New lit elements modules - `@wirestate/lit` and `@wirestate/lit-signals`
|
|
@@ -8,6 +8,21 @@
|
|
|
8
8
|
- `WireScope`: add new event/command/query subscribe-unsubscribe methods
|
|
9
9
|
- Export more alias / methods from `@wirestate/core`
|
|
10
10
|
- Export more alias / methods from `@wirestate/react-mobx`
|
|
11
|
+
- Export missing methods typing for `@wirestate/core`
|
|
12
|
+
- Extensive JSDoc coverage for wirestate packages
|
|
13
|
+
- `createIocContainer`: Removed in favor of `createContainer`
|
|
14
|
+
- `createContainer`: Added ability to instantly provide and activate entries, targeted seeds
|
|
15
|
+
- `createInjectablesProvider`: Removed.
|
|
16
|
+
- `IocProvider`: Removed
|
|
17
|
+
- `useRootContainer`: Added separate hook for store management in React tree
|
|
18
|
+
- `ContainerProvider`: Simpler provider for containers.
|
|
19
|
+
- `SubContainerProvider`: Added component solving problems of removed `createInjectablesProvider`
|
|
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`
|
|
11
26
|
|
|
12
27
|
## 0.6.3
|
|
13
28
|
|
|
@@ -70,6 +85,6 @@
|
|
|
70
85
|
- useService -> useInjection
|
|
71
86
|
- AbstractService::getService -> AbstractService::resolve
|
|
72
87
|
|
|
73
|
-
## 0.1.
|
|
88
|
+
## 0.1.0
|
|
74
89
|
|
|
75
90
|
- Initial release
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# @wirestate/lit
|
|
1
|
+
# @wirestate/lit [[monorepo](https://github.com/Neloreck/wirestate)] [[docs](https://neloreck.github.io/wirestate/)]
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@wirestate/lit)
|
|
4
4
|
[](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
|
|
22
|
-
- **
|
|
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
|
-
### `@
|
|
27
|
+
### `@containerProvide(options)` / `useContainerProvision(host, options)`
|
|
28
28
|
|
|
29
|
-
Provides
|
|
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
|
-
import { LitElement, html } from
|
|
33
|
-
import { customElement } from
|
|
34
|
-
import {
|
|
34
|
+
import { LitElement, html } from "lit";
|
|
35
|
+
import { customElement } from "lit/decorators.js";
|
|
36
|
+
import { containerProvide, ContainerProvider } from "@wirestate/lit";
|
|
35
37
|
|
|
36
|
-
@customElement(
|
|
38
|
+
@customElement("my-app")
|
|
37
39
|
class MyApp extends LitElement {
|
|
38
|
-
@
|
|
39
|
-
|
|
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,69 +50,81 @@ class MyApp extends LitElement {
|
|
|
44
50
|
}
|
|
45
51
|
```
|
|
46
52
|
|
|
47
|
-
### `@
|
|
53
|
+
### `@subContainerProvide(options)` / `useSubContainerProvider(host, options)`
|
|
48
54
|
|
|
49
|
-
|
|
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
|
-
import { LitElement } from
|
|
55
|
-
import { customElement } from
|
|
56
|
-
import {
|
|
60
|
+
import { LitElement } from "lit";
|
|
61
|
+
import { customElement } from "lit/decorators.js";
|
|
62
|
+
import { subContainerProvide, SubContainerProvider } from "@wirestate/lit";
|
|
57
63
|
|
|
58
|
-
import { AuthService, UserService } from
|
|
64
|
+
import { AuthService, UserService } from "./services";
|
|
59
65
|
|
|
60
|
-
@customElement(
|
|
66
|
+
@customElement("my-app")
|
|
61
67
|
class MyApp extends LitElement {
|
|
62
|
-
@
|
|
63
|
-
|
|
68
|
+
@subContainerProvide({
|
|
69
|
+
options: {
|
|
70
|
+
entries: [AuthService, UserService],
|
|
71
|
+
activate: [AuthService],
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
public containerProvider!: SubContainerProvider;
|
|
64
75
|
}
|
|
65
76
|
```
|
|
66
77
|
|
|
67
78
|
Using the hook:
|
|
68
79
|
|
|
69
80
|
```typescript
|
|
70
|
-
import { LitElement } from
|
|
71
|
-
import {
|
|
81
|
+
import { LitElement } from "lit";
|
|
82
|
+
import { useSubContainerProvider } from "@wirestate/lit";
|
|
72
83
|
|
|
73
|
-
import { AuthService, UserService } from
|
|
84
|
+
import { AuthService, UserService } from "./services";
|
|
74
85
|
|
|
75
86
|
class MyApp extends LitElement {
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
96
|
+
Using the provider directly:
|
|
84
97
|
|
|
85
98
|
```typescript
|
|
86
|
-
import { LitElement } from
|
|
87
|
-
import {
|
|
99
|
+
import { LitElement } from "lit";
|
|
100
|
+
import { SubContainerProvider } from "@wirestate/lit";
|
|
88
101
|
|
|
89
|
-
import { AuthService, UserService } from
|
|
102
|
+
import { AuthService, UserService } from "./services";
|
|
90
103
|
|
|
91
104
|
class MyApp extends LitElement {
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
114
|
+
To seed the child container during creation, pass `seeds` inside `options`:
|
|
100
115
|
|
|
101
116
|
```typescript
|
|
102
|
-
import { LitElement } from
|
|
103
|
-
import {
|
|
117
|
+
import { LitElement } from "lit";
|
|
118
|
+
import { useSubContainerProvider } from "@wirestate/lit";
|
|
104
119
|
|
|
105
|
-
import { AuthService, UserService } from
|
|
120
|
+
import { AuthService, UserService } from "./services";
|
|
106
121
|
|
|
107
122
|
class MyApp extends LitElement {
|
|
108
|
-
private
|
|
109
|
-
|
|
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,16 +133,16 @@ class MyApp extends LitElement {
|
|
|
115
133
|
|
|
116
134
|
### `@injection(optionsOrId)` / `useInjection(host, optionsOrId)`
|
|
117
135
|
|
|
118
|
-
Injects a service from the nearest
|
|
136
|
+
Injects a service from the nearest parent container. Supports both options object and direct service identifier.
|
|
119
137
|
|
|
120
138
|
```typescript
|
|
121
|
-
import { LitElement, html } from
|
|
122
|
-
import { customElement } from
|
|
123
|
-
import { injection } from
|
|
139
|
+
import { LitElement, html } from "lit";
|
|
140
|
+
import { customElement } from "lit/decorators.js";
|
|
141
|
+
import { injection } from "@wirestate/lit";
|
|
124
142
|
|
|
125
|
-
import { MyService } from
|
|
143
|
+
import { MyService } from "./services";
|
|
126
144
|
|
|
127
|
-
@customElement(
|
|
145
|
+
@customElement("my-component")
|
|
128
146
|
class MyComponent extends LitElement {
|
|
129
147
|
// Using identifier:
|
|
130
148
|
@injection(MyService)
|
|
@@ -140,13 +158,13 @@ class MyComponent extends LitElement {
|
|
|
140
158
|
}
|
|
141
159
|
```
|
|
142
160
|
|
|
143
|
-
Using the
|
|
161
|
+
Using the hook:
|
|
144
162
|
|
|
145
163
|
```typescript
|
|
146
|
-
import { LitElement, html } from
|
|
147
|
-
import { useInjection } from
|
|
164
|
+
import { LitElement, html } from "lit";
|
|
165
|
+
import { useInjection } from "@wirestate/lit";
|
|
148
166
|
|
|
149
|
-
import { MyService } from
|
|
167
|
+
import { MyService } from "./services";
|
|
150
168
|
|
|
151
169
|
class MyComponent extends LitElement {
|
|
152
170
|
// Using identifier:
|
|
@@ -165,18 +183,18 @@ 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
|
-
import { LitElement } from
|
|
172
|
-
import { onEvent } from
|
|
189
|
+
import { LitElement } from "lit";
|
|
190
|
+
import { onEvent } from "@wirestate/lit";
|
|
173
191
|
|
|
174
|
-
import { UserLoggedInEvent } from
|
|
192
|
+
import { UserLoggedInEvent } from "./events";
|
|
175
193
|
|
|
176
194
|
class MyListener extends LitElement {
|
|
177
195
|
@onEvent("USER_LOGGED_IN")
|
|
178
196
|
private handleLogin(event: UserLoggedInEvent) {
|
|
179
|
-
console.log(
|
|
197
|
+
console.log("User logged in:", event.payload);
|
|
180
198
|
}
|
|
181
199
|
}
|
|
182
200
|
```
|
|
@@ -184,26 +202,26 @@ class MyListener extends LitElement {
|
|
|
184
202
|
Using the controller:
|
|
185
203
|
|
|
186
204
|
```typescript
|
|
187
|
-
import { LitElement } from
|
|
188
|
-
import { useOnEvents } from
|
|
205
|
+
import { LitElement } from "lit";
|
|
206
|
+
import { useOnEvents } from "@wirestate/lit";
|
|
189
207
|
|
|
190
208
|
class MyListener extends LitElement {
|
|
191
209
|
private events = useOnEvents(this, {
|
|
192
|
-
handler: (event) => console.log(
|
|
210
|
+
handler: (event) => console.log("Event received:", event),
|
|
193
211
|
});
|
|
194
212
|
}
|
|
195
213
|
```
|
|
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
|
-
import { LitElement } from
|
|
203
|
-
import { onCommand } from
|
|
220
|
+
import { LitElement } from "lit";
|
|
221
|
+
import { onCommand } from "@wirestate/lit";
|
|
204
222
|
|
|
205
223
|
class MyCommander extends LitElement {
|
|
206
|
-
@onCommand(
|
|
224
|
+
@onCommand("RESET_STATE")
|
|
207
225
|
private handleReset() {
|
|
208
226
|
// perform reset
|
|
209
227
|
}
|
|
@@ -212,14 +230,14 @@ 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
|
-
import { LitElement } from
|
|
219
|
-
import { onQuery } from
|
|
236
|
+
import { LitElement } from "lit";
|
|
237
|
+
import { onQuery } from "@wirestate/lit";
|
|
220
238
|
|
|
221
239
|
class MyQuerier extends LitElement {
|
|
222
|
-
@onQuery(
|
|
240
|
+
@onQuery("GET_VIEW_PORT")
|
|
223
241
|
private handleGetViewport() {
|
|
224
242
|
return { width: window.innerWidth, height: window.innerHeight };
|
|
225
243
|
}
|
|
@@ -233,9 +251,9 @@ class MyQuerier extends LitElement {
|
|
|
233
251
|
Creates a test fixture with a provider element and an IoC container. Useful for unit testing components that use injections.
|
|
234
252
|
|
|
235
253
|
```typescript
|
|
236
|
-
import { createLitProvision } from
|
|
254
|
+
import { createLitProvision } from "@wirestate/lit/test-utils";
|
|
237
255
|
|
|
238
|
-
describe(
|
|
256
|
+
describe("MyComponent", () => {
|
|
239
257
|
let fixture: ReturnType<typeof createLitProvision>;
|
|
240
258
|
|
|
241
259
|
beforeEach(() => {
|
|
@@ -246,8 +264,8 @@ describe('MyComponent', () => {
|
|
|
246
264
|
fixture.cleanup();
|
|
247
265
|
});
|
|
248
266
|
|
|
249
|
-
it(
|
|
250
|
-
const el = document.createElement(
|
|
267
|
+
it("should work", () => {
|
|
268
|
+
const el = document.createElement("my-component");
|
|
251
269
|
fixture.provider.appendChild(el);
|
|
252
270
|
// ...
|
|
253
271
|
});
|