@wirestate/lit 0.6.0 → 0.7.0-experimental.1
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 +21 -1
- package/README.md +246 -10
- package/cjs/development/index.js +788 -58
- 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 +59 -0
- package/esm/development/commands/on-command-controller.js.map +1 -0
- package/esm/development/commands/on-command.js +46 -0
- package/esm/development/commands/on-command.js.map +1 -0
- package/esm/development/commands/use-on-command.js +31 -0
- package/esm/development/commands/use-on-command.js.map +1 -0
- package/esm/development/consumption/injection.js +43 -9
- package/esm/development/consumption/injection.js.map +1 -1
- package/esm/development/consumption/use-injection.js +40 -6
- package/esm/development/consumption/use-injection.js.map +1 -1
- package/esm/development/context/ioc-context.js +12 -2
- package/esm/development/context/ioc-context.js.map +1 -1
- package/esm/development/error/error-code.js +4 -0
- package/esm/development/error/error-code.js.map +1 -0
- package/esm/development/events/on-event-controller.js +68 -0
- package/esm/development/events/on-event-controller.js.map +1 -0
- package/esm/development/events/on-event.js +68 -0
- package/esm/development/events/on-event.js.map +1 -0
- package/esm/development/events/use-on-events.js +42 -0
- package/esm/development/events/use-on-events.js.map +1 -0
- package/esm/development/index.js +16 -4
- package/esm/development/index.js.map +1 -1
- package/esm/development/provision/injectables-provide.js +47 -0
- package/esm/development/provision/injectables-provide.js.map +1 -0
- package/esm/development/provision/injectables-provider-controller.js +123 -0
- package/esm/development/provision/injectables-provider-controller.js.map +1 -0
- package/esm/development/provision/ioc-provide.js +58 -0
- package/esm/development/provision/ioc-provide.js.map +1 -0
- package/esm/development/provision/ioc-provider-controller.js +75 -0
- package/esm/development/provision/ioc-provider-controller.js.map +1 -0
- package/esm/development/provision/use-injectables-provider.js +27 -0
- package/esm/development/provision/use-injectables-provider.js.map +1 -0
- package/esm/development/provision/use-ioc-provision.js +27 -0
- package/esm/development/provision/use-ioc-provision.js.map +1 -0
- package/esm/development/queries/on-query-controller.js +59 -0
- package/esm/development/queries/on-query-controller.js.map +1 -0
- package/esm/development/queries/on-query.js +46 -0
- package/esm/development/queries/on-query.js.map +1 -0
- package/esm/development/queries/use-on-query.js +31 -0
- package/esm/development/queries/use-on-query.js.map +1 -0
- package/esm/production/commands/on-command-controller.js +1 -0
- package/esm/production/commands/on-command-controller.js.map +1 -0
- package/esm/production/commands/on-command.js +1 -0
- package/esm/production/commands/on-command.js.map +1 -0
- package/esm/production/commands/use-on-command.js +1 -0
- package/esm/production/commands/use-on-command.js.map +1 -0
- package/esm/production/consumption/injection.js +1 -1
- package/esm/production/consumption/injection.js.map +1 -1
- package/esm/production/consumption/use-injection.js +1 -1
- package/esm/production/consumption/use-injection.js.map +1 -1
- package/esm/production/context/ioc-context.js +1 -1
- package/esm/production/context/ioc-context.js.map +1 -1
- package/esm/production/error/error-code.js +1 -0
- package/esm/production/error/error-code.js.map +1 -0
- package/esm/production/events/on-event-controller.js +1 -0
- package/esm/production/events/on-event-controller.js.map +1 -0
- package/esm/production/events/on-event.js +1 -0
- package/esm/production/events/on-event.js.map +1 -0
- package/esm/production/events/use-on-events.js +1 -0
- package/esm/production/events/use-on-events.js.map +1 -0
- package/esm/production/index.js +1 -1
- package/esm/production/provision/injectables-provide.js +1 -0
- package/esm/production/provision/injectables-provide.js.map +1 -0
- package/esm/production/provision/injectables-provider-controller.js +1 -0
- package/esm/production/provision/injectables-provider-controller.js.map +1 -0
- package/esm/production/provision/ioc-provide.js +1 -0
- package/esm/production/provision/ioc-provide.js.map +1 -0
- package/esm/production/provision/ioc-provider-controller.js +1 -0
- package/esm/production/provision/ioc-provider-controller.js.map +1 -0
- package/esm/production/provision/use-injectables-provider.js +1 -0
- package/esm/production/provision/use-injectables-provider.js.map +1 -0
- package/esm/production/provision/use-ioc-provision.js +1 -0
- package/esm/production/provision/use-ioc-provision.js.map +1 -0
- package/esm/production/queries/on-query-controller.js +1 -0
- package/esm/production/queries/on-query-controller.js.map +1 -0
- package/esm/production/queries/on-query.js +1 -0
- package/esm/production/queries/on-query.js.map +1 -0
- package/esm/production/queries/use-on-query.js +1 -0
- package/esm/production/queries/use-on-query.js.map +1 -0
- package/index.d.ts +730 -29
- package/package.json +1 -1
- package/esm/development/provision/container-provider-controller.js +0 -41
- package/esm/development/provision/container-provider-controller.js.map +0 -1
- package/esm/development/provision/services-provider-controller.js +0 -63
- package/esm/development/provision/services-provider-controller.js.map +0 -1
- package/esm/development/provision/use-container-provision.js +0 -9
- package/esm/development/provision/use-container-provision.js.map +0 -1
- package/esm/production/provision/container-provider-controller.js +0 -1
- package/esm/production/provision/container-provider-controller.js.map +0 -1
- package/esm/production/provision/services-provider-controller.js +0 -1
- package/esm/production/provision/services-provider-controller.js.map +0 -1
- package/esm/production/provision/use-container-provision.js +0 -1
- package/esm/production/provision/use-container-provision.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## 0.7.0
|
|
2
|
+
|
|
3
|
+
- Add `useScope` in `@wirestate/react`
|
|
4
|
+
- New lit elements modules - `@wirestate/lit` and `@wirestate/lit-signals`
|
|
5
|
+
- `EventBus`: add `unsubscribe` method for explicit handler removal by reference
|
|
6
|
+
- `QueryBus`: add `unregister` method for explicit handler removal by type and reference
|
|
7
|
+
- `CommandBus`: add `unregister` method for explicit handler removal by type and reference
|
|
8
|
+
- `WireScope`: add new event/command/query subscribe-unsubscribe methods
|
|
9
|
+
- Export more alias / methods from `@wirestate/core`
|
|
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`: Added ability to instantly provide and activate entries, targeted seeds
|
|
14
|
+
- `createInjectablesProvider`: Removed.
|
|
15
|
+
- `IocProvider`: Removed
|
|
16
|
+
- `useRootContainer`: Added separate hook for store management in React tree
|
|
17
|
+
- `ContainerProvider`: Simpler provider for containers.
|
|
18
|
+
- `SubContainerProvider`: Added component solving problems of removed `createInjectablesProvider`
|
|
19
|
+
- `ContainerActivator`: Added separate activation component
|
|
20
|
+
|
|
1
21
|
## 0.6.3
|
|
2
22
|
|
|
3
23
|
- Update readme files for each module
|
|
@@ -59,6 +79,6 @@
|
|
|
59
79
|
- useService -> useInjection
|
|
60
80
|
- AbstractService::getService -> AbstractService::resolve
|
|
61
81
|
|
|
62
|
-
## 0.1.
|
|
82
|
+
## 0.1.0
|
|
63
83
|
|
|
64
84
|
- Initial release
|
package/README.md
CHANGED
|
@@ -1,23 +1,259 @@
|
|
|
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.
|
|
7
|
-
Planned — not yet implemented.
|
|
6
|
+
Lit elements integration for wirestate. Provides dependency injection and messaging for Lit components.
|
|
8
7
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
- Base `LitElement` classes and mixins for resolving services from the wirestate DI container
|
|
12
|
-
- Lit-compatible equivalents of the React providers from `@wirestate/react`
|
|
13
|
-
- Lifecycle integration: activate/deactivate services on element connect/disconnect
|
|
14
|
-
|
|
15
|
-
## Installation (upcoming)
|
|
8
|
+
## Installation
|
|
16
9
|
|
|
17
10
|
```bash
|
|
18
11
|
npm install @wirestate/core @wirestate/lit lit reflect-metadata
|
|
19
12
|
```
|
|
20
13
|
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Dependency Injection**: Inject services from the IoC container using `@injection` decorator or `useInjection` controller.
|
|
17
|
+
- **Messaging**:
|
|
18
|
+
- **Events**: Subscribe to events from the global event bus using `@onEvent` or `useOnEvents`.
|
|
19
|
+
- **Commands**: Register command handlers using `@onCommand` or `useOnCommand`.
|
|
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`.
|
|
23
|
+
- **Test Utilities**: Simplified setup for unit testing components with IoC dependencies.
|
|
24
|
+
|
|
25
|
+
## Provisioning
|
|
26
|
+
|
|
27
|
+
### `@iocProvide(options?)` / `useIocProvision(host, options?)`
|
|
28
|
+
|
|
29
|
+
Provides an IoC container to the component tree. It uses Lit Context to propagate the container to child elements.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { LitElement, html } from "lit";
|
|
33
|
+
import { customElement } from "lit/decorators.js";
|
|
34
|
+
import { iocProvide, IocProviderController } from "@wirestate/lit";
|
|
35
|
+
|
|
36
|
+
@customElement("my-app")
|
|
37
|
+
class MyApp extends LitElement {
|
|
38
|
+
@iocProvide()
|
|
39
|
+
private ioc!: IocProviderController;
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
return html`<my-component></my-component>`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `@injectablesProvide(options)` / `useInjectablesProvider(host, options)`
|
|
48
|
+
|
|
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.
|
|
50
|
+
|
|
51
|
+
Using the decorator (accessor):
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { LitElement } from "lit";
|
|
55
|
+
import { customElement } from "lit/decorators.js";
|
|
56
|
+
import { injectablesProvide, InjectablesProviderController } from "@wirestate/lit";
|
|
57
|
+
|
|
58
|
+
import { AuthService, UserService } from "./services";
|
|
59
|
+
|
|
60
|
+
@customElement("my-app")
|
|
61
|
+
class MyApp extends LitElement {
|
|
62
|
+
@injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
|
|
63
|
+
public services!: InjectablesProviderController<MyApp>;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Using the hook:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { LitElement } from "lit";
|
|
71
|
+
import { useInjectablesProvider } from "@wirestate/lit";
|
|
72
|
+
|
|
73
|
+
import { AuthService, UserService } from "./services";
|
|
74
|
+
|
|
75
|
+
class MyApp extends LitElement {
|
|
76
|
+
private services = useInjectablesProvider(this, {
|
|
77
|
+
entries: [AuthService, UserService],
|
|
78
|
+
activate: [AuthService],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Using the controller directly:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { LitElement } from "lit";
|
|
87
|
+
import { InjectablesProviderController } from "@wirestate/lit";
|
|
88
|
+
|
|
89
|
+
import { AuthService, UserService } from "./services";
|
|
90
|
+
|
|
91
|
+
class MyApp extends LitElement {
|
|
92
|
+
private services = new InjectablesProviderController(this, {
|
|
93
|
+
entries: [AuthService, UserService],
|
|
94
|
+
activate: [AuthService],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
To bind into a specific container instead of the nearest provider context, pass the `into` option:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { LitElement } from "lit";
|
|
103
|
+
import { useInjectablesProvider } from "@wirestate/lit";
|
|
104
|
+
|
|
105
|
+
import { AuthService, UserService } from "./services";
|
|
106
|
+
|
|
107
|
+
class MyApp extends LitElement {
|
|
108
|
+
private services = useInjectablesProvider(this, {
|
|
109
|
+
entries: [AuthService, UserService],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Injection
|
|
115
|
+
|
|
116
|
+
### `@injection(optionsOrId)` / `useInjection(host, optionsOrId)`
|
|
117
|
+
|
|
118
|
+
Injects a service from the nearest IoC container. Supports both options object and direct service identifier.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { LitElement, html } from "lit";
|
|
122
|
+
import { customElement } from "lit/decorators.js";
|
|
123
|
+
import { injection } from "@wirestate/lit";
|
|
124
|
+
|
|
125
|
+
import { MyService } from "./services";
|
|
126
|
+
|
|
127
|
+
@customElement("my-component")
|
|
128
|
+
class MyComponent extends LitElement {
|
|
129
|
+
// Using identifier:
|
|
130
|
+
@injection(MyService)
|
|
131
|
+
private myService!: MyService;
|
|
132
|
+
|
|
133
|
+
// Using options object:
|
|
134
|
+
@injection({ injectionId: MyService, once: true })
|
|
135
|
+
private onceService!: MyService;
|
|
136
|
+
|
|
137
|
+
render() {
|
|
138
|
+
return html`<div>${this.myService.getData()}</div>`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Using the controller:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { LitElement, html } from "lit";
|
|
147
|
+
import { useInjection } from "@wirestate/lit";
|
|
148
|
+
|
|
149
|
+
import { MyService } from "./services";
|
|
150
|
+
|
|
151
|
+
class MyComponent extends LitElement {
|
|
152
|
+
// Using identifier:
|
|
153
|
+
private myService = useInjection(this, MyService);
|
|
154
|
+
|
|
155
|
+
// Using options object:
|
|
156
|
+
private onceService = useInjection(this, { injectionId: MyService, once: true });
|
|
157
|
+
|
|
158
|
+
render() {
|
|
159
|
+
return html`<div>${this.myService.value.getData()}</div>`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Messaging
|
|
165
|
+
|
|
166
|
+
### Events
|
|
167
|
+
|
|
168
|
+
Subscribe to events from the event bus using `@onEvent` decorator or `useOnEvents` controller.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { LitElement } from "lit";
|
|
172
|
+
import { onEvent } from "@wirestate/lit";
|
|
173
|
+
|
|
174
|
+
import { UserLoggedInEvent } from "./events";
|
|
175
|
+
|
|
176
|
+
class MyListener extends LitElement {
|
|
177
|
+
@onEvent("USER_LOGGED_IN")
|
|
178
|
+
private handleLogin(event: UserLoggedInEvent) {
|
|
179
|
+
console.log("User logged in:", event.payload);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Using the controller:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { LitElement } from "lit";
|
|
188
|
+
import { useOnEvents } from "@wirestate/lit";
|
|
189
|
+
|
|
190
|
+
class MyListener extends LitElement {
|
|
191
|
+
private events = useOnEvents(this, {
|
|
192
|
+
handler: (event) => console.log("Event received:", event),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Commands
|
|
198
|
+
|
|
199
|
+
Register a handler for a specific command type.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { LitElement } from "lit";
|
|
203
|
+
import { onCommand } from "@wirestate/lit";
|
|
204
|
+
|
|
205
|
+
class MyCommander extends LitElement {
|
|
206
|
+
@onCommand("RESET_STATE")
|
|
207
|
+
private handleReset() {
|
|
208
|
+
// perform reset
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Queries
|
|
214
|
+
|
|
215
|
+
Register a handler for a specific query type.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { LitElement } from "lit";
|
|
219
|
+
import { onQuery } from "@wirestate/lit";
|
|
220
|
+
|
|
221
|
+
class MyQuerier extends LitElement {
|
|
222
|
+
@onQuery("GET_VIEW_PORT")
|
|
223
|
+
private handleGetViewport() {
|
|
224
|
+
return { width: window.innerWidth, height: window.innerHeight };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Test Utilities
|
|
230
|
+
|
|
231
|
+
### `createLitProvision(container?)`
|
|
232
|
+
|
|
233
|
+
Creates a test fixture with a provider element and an IoC container. Useful for unit testing components that use injections.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { createLitProvision } from "@wirestate/lit/test-utils";
|
|
237
|
+
|
|
238
|
+
describe("MyComponent", () => {
|
|
239
|
+
let fixture: ReturnType<typeof createLitProvision>;
|
|
240
|
+
|
|
241
|
+
beforeEach(() => {
|
|
242
|
+
fixture = createLitProvision();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
afterEach(() => {
|
|
246
|
+
fixture.cleanup();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("should work", () => {
|
|
250
|
+
const el = document.createElement("my-component");
|
|
251
|
+
fixture.provider.appendChild(el);
|
|
252
|
+
// ...
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
21
257
|
## License
|
|
22
258
|
|
|
23
259
|
MIT
|