@wirestate/core 0.6.3 → 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 +48 -37
- package/cjs/development/index.js +325 -91
- package/cjs/development/index.js.map +1 -1
- package/cjs/development/lib.js +1033 -248
- package/cjs/development/lib.js.map +1 -1
- package/cjs/development/test-utils.js +95 -32
- package/cjs/development/test-utils.js.map +1 -1
- package/cjs/production/index.js +1 -1
- package/cjs/production/index.js.map +1 -1
- package/cjs/production/lib.js +1 -1
- package/cjs/production/lib.js.map +1 -1
- package/cjs/production/test-utils.js +1 -1
- package/cjs/production/test-utils.js.map +1 -1
- package/esm/development/alias.js +10 -1
- package/esm/development/alias.js.map +1 -1
- package/esm/development/bind/bind-constant.js +25 -4
- package/esm/development/bind/bind-constant.js.map +1 -1
- package/esm/development/bind/bind-dynamic-value.js +27 -7
- package/esm/development/bind/bind-dynamic-value.js.map +1 -1
- package/esm/development/bind/bind-entry.js +50 -17
- package/esm/development/bind/bind-entry.js.map +1 -1
- package/esm/development/bind/bind-service.js +71 -19
- package/esm/development/bind/bind-service.js.map +1 -1
- package/esm/development/bind/get-entry-token.js +21 -5
- package/esm/development/bind/get-entry-token.js.map +1 -1
- package/esm/development/commands/command-bus.js +93 -46
- package/esm/development/commands/command-bus.js.map +1 -1
- package/esm/development/commands/command-optional.js +28 -5
- package/esm/development/commands/command-optional.js.map +1 -1
- package/esm/development/commands/command.js +26 -5
- package/esm/development/commands/command.js.map +1 -1
- package/esm/development/commands/get-command-handler-metadata.js +8 -3
- package/esm/development/commands/get-command-handler-metadata.js.map +1 -1
- package/esm/development/commands/on-command.js +19 -3
- package/esm/development/commands/on-command.js.map +1 -1
- package/esm/development/container/create-base-container.js +57 -0
- package/esm/development/container/create-base-container.js.map +1 -0
- package/esm/development/container/create-container.js +78 -0
- package/esm/development/container/create-container.js.map +1 -0
- package/esm/development/container/wire-scope.js +236 -54
- package/esm/development/container/wire-scope.js.map +1 -1
- package/esm/development/error/error-code.js +2 -1
- package/esm/development/error/error-code.js.map +1 -1
- package/esm/development/error/wirestate-error.js +25 -4
- package/esm/development/error/wirestate-error.js.map +1 -1
- package/esm/development/events/build-event-dispatcher.js +20 -2
- package/esm/development/events/build-event-dispatcher.js.map +1 -1
- package/esm/development/events/emit-event.js +18 -5
- package/esm/development/events/emit-event.js.map +1 -1
- package/esm/development/events/event-bus.js +58 -9
- package/esm/development/events/event-bus.js.map +1 -1
- package/esm/development/events/get-event-handler-metadata.js +19 -4
- package/esm/development/events/get-event-handler-metadata.js.map +1 -1
- package/esm/development/events/on-event.js +31 -2
- package/esm/development/events/on-event.js.map +1 -1
- package/esm/development/index.js +5 -4
- package/esm/development/index.js.map +1 -1
- package/esm/development/queries/get-query-handler-metadata.js +20 -4
- package/esm/development/queries/get-query-handler-metadata.js.map +1 -1
- package/esm/development/queries/on-query.js +24 -2
- package/esm/development/queries/on-query.js.map +1 -1
- package/esm/development/queries/query-bus.js +82 -31
- package/esm/development/queries/query-bus.js.map +1 -1
- package/esm/development/queries/query-optional.js +19 -5
- package/esm/development/queries/query-optional.js.map +1 -1
- package/esm/development/queries/query.js +25 -5
- package/esm/development/queries/query.js.map +1 -1
- package/esm/development/registry.js +81 -24
- package/esm/development/registry.js.map +1 -1
- package/esm/development/seeds/apply-seeds.js +19 -5
- package/esm/development/seeds/apply-seeds.js.map +1 -1
- package/esm/development/seeds/apply-shared-seed.js +16 -4
- package/esm/development/seeds/apply-shared-seed.js.map +1 -1
- package/esm/development/seeds/tokens.js +31 -0
- package/esm/development/seeds/tokens.js.map +1 -0
- package/esm/development/seeds/unapply-seeds.js +16 -5
- package/esm/development/seeds/unapply-seeds.js.map +1 -1
- package/esm/development/service/get-activated-handler-metadata.js +16 -4
- package/esm/development/service/get-activated-handler-metadata.js.map +1 -1
- package/esm/development/service/get-deactivation-handler-metadata.js +16 -4
- package/esm/development/service/get-deactivation-handler-metadata.js.map +1 -1
- package/esm/development/service/on-activated.js +22 -2
- package/esm/development/service/on-activated.js.map +1 -1
- package/esm/development/service/on-deactivation.js +22 -2
- package/esm/development/service/on-deactivation.js.map +1 -1
- package/esm/development/test-utils/mock-bind-entry.js +17 -7
- package/esm/development/test-utils/mock-bind-entry.js.map +1 -1
- package/esm/development/test-utils/mock-bind-service.js +17 -7
- package/esm/development/test-utils/mock-bind-service.js.map +1 -1
- package/esm/development/test-utils/mock-container.js +25 -8
- package/esm/development/test-utils/mock-container.js.map +1 -1
- package/esm/development/test-utils/mock-service.js +18 -5
- package/esm/development/test-utils/mock-service.js.map +1 -1
- package/esm/development/test-utils/mock-unbind-service.js +16 -3
- package/esm/development/test-utils/mock-unbind-service.js.map +1 -1
- package/esm/development/types/commands.js +6 -1
- package/esm/development/types/commands.js.map +1 -1
- package/esm/production/alias.js +1 -1
- package/esm/production/alias.js.map +1 -1
- package/esm/production/bind/bind-constant.js +1 -1
- package/esm/production/bind/bind-constant.js.map +1 -1
- package/esm/production/bind/bind-dynamic-value.js +1 -1
- package/esm/production/bind/bind-dynamic-value.js.map +1 -1
- package/esm/production/bind/bind-entry.js +1 -1
- package/esm/production/bind/bind-entry.js.map +1 -1
- package/esm/production/bind/bind-service.js.map +1 -1
- package/esm/production/bind/get-entry-token.js.map +1 -1
- package/esm/production/commands/command-bus.js +1 -1
- package/esm/production/commands/command-bus.js.map +1 -1
- package/esm/production/commands/command-optional.js.map +1 -1
- package/esm/production/commands/command.js.map +1 -1
- package/esm/production/commands/get-command-handler-metadata.js.map +1 -1
- package/esm/production/commands/on-command.js.map +1 -1
- package/esm/production/container/create-base-container.js +1 -0
- package/esm/production/container/create-base-container.js.map +1 -0
- package/esm/production/container/create-container.js +1 -0
- package/esm/production/container/create-container.js.map +1 -0
- package/esm/production/container/wire-scope.js +1 -1
- package/esm/production/container/wire-scope.js.map +1 -1
- package/esm/production/error/error-code.js +1 -1
- package/esm/production/error/error-code.js.map +1 -1
- package/esm/production/error/wirestate-error.js.map +1 -1
- package/esm/production/events/build-event-dispatcher.js.map +1 -1
- package/esm/production/events/emit-event.js.map +1 -1
- package/esm/production/events/event-bus.js +1 -1
- package/esm/production/events/event-bus.js.map +1 -1
- package/esm/production/events/get-event-handler-metadata.js.map +1 -1
- package/esm/production/events/on-event.js.map +1 -1
- package/esm/production/index.js +1 -1
- package/esm/production/queries/get-query-handler-metadata.js.map +1 -1
- package/esm/production/queries/on-query.js.map +1 -1
- package/esm/production/queries/query-bus.js +1 -1
- package/esm/production/queries/query-bus.js.map +1 -1
- package/esm/production/queries/query-optional.js.map +1 -1
- package/esm/production/queries/query.js.map +1 -1
- package/esm/production/registry.js +1 -1
- package/esm/production/registry.js.map +1 -1
- package/esm/production/seeds/apply-seeds.js +1 -1
- package/esm/production/seeds/apply-seeds.js.map +1 -1
- package/esm/production/seeds/apply-shared-seed.js +1 -1
- package/esm/production/seeds/apply-shared-seed.js.map +1 -1
- package/esm/production/seeds/tokens.js +1 -0
- package/esm/production/seeds/tokens.js.map +1 -0
- package/esm/production/seeds/unapply-seeds.js +1 -1
- package/esm/production/seeds/unapply-seeds.js.map +1 -1
- package/esm/production/service/get-activated-handler-metadata.js.map +1 -1
- package/esm/production/service/get-deactivation-handler-metadata.js.map +1 -1
- package/esm/production/service/on-activated.js.map +1 -1
- package/esm/production/service/on-deactivation.js.map +1 -1
- package/esm/production/test-utils/mock-bind-entry.js +1 -1
- package/esm/production/test-utils/mock-bind-entry.js.map +1 -1
- package/esm/production/test-utils/mock-bind-service.js +1 -1
- package/esm/production/test-utils/mock-bind-service.js.map +1 -1
- package/esm/production/test-utils/mock-container.js +1 -1
- package/esm/production/test-utils/mock-container.js.map +1 -1
- package/esm/production/test-utils/mock-service.js.map +1 -1
- package/esm/production/test-utils/mock-unbind-service.js.map +1 -1
- package/esm/production/types/commands.js.map +1 -1
- package/index.d.ts +1159 -229
- package/lib.d.ts +128 -9
- package/package.json +1 -2
- package/test-utils.d.ts +140 -40
- package/esm/development/container/create-ioc-container.js +0 -35
- package/esm/development/container/create-ioc-container.js.map +0 -1
- package/esm/production/container/create-ioc-container.js +0 -1
- package/esm/production/container/create-ioc-container.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,4 +1,4 @@
|
|
|
1
|
-
# @wirestate/core
|
|
1
|
+
# @wirestate/core [[monorepo](https://github.com/Neloreck/wirestate)] [[docs](https://neloreck.github.io/wirestate/)]
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@wirestate/core)
|
|
4
4
|
[](https://github.com/Neloreck/wirestate/blob/master/LICENSE)
|
|
@@ -16,7 +16,7 @@ npm install @wirestate/core reflect-metadata
|
|
|
16
16
|
Import `reflect-metadata` once at your application entry point, before any wirestate imports:
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
import
|
|
19
|
+
import "reflect-metadata";
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Services
|
|
@@ -24,15 +24,13 @@ import 'reflect-metadata';
|
|
|
24
24
|
Services are plain classes decorated with `@Injectable`. Each service may inject a `WireScope` which provides access to the event, command, and query buses and to other services in the container.
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
import { Injectable, Inject, WireScope } from
|
|
27
|
+
import { Injectable, Inject, WireScope } from "@wirestate/core";
|
|
28
28
|
|
|
29
29
|
@Injectable()
|
|
30
30
|
export class CounterService {
|
|
31
31
|
public count = 0;
|
|
32
32
|
|
|
33
|
-
public constructor(
|
|
34
|
-
@Inject(WireScope) private scope: WireScope
|
|
35
|
-
) {}
|
|
33
|
+
public constructor(@Inject(WireScope) private scope: WireScope) {}
|
|
36
34
|
|
|
37
35
|
public increment(): void {
|
|
38
36
|
this.count++;
|
|
@@ -43,13 +41,17 @@ export class CounterService {
|
|
|
43
41
|
## Container
|
|
44
42
|
|
|
45
43
|
```ts
|
|
46
|
-
import { createIocContainer, bindService } from
|
|
44
|
+
import { createIocContainer, bindService } from "@wirestate/core";
|
|
47
45
|
|
|
48
|
-
const container = createIocContainer(
|
|
46
|
+
const container = createIocContainer({
|
|
47
|
+
seed: { baseUrl: "https://example.com" },
|
|
48
|
+
entries: [CounterService],
|
|
49
|
+
});
|
|
49
50
|
|
|
50
|
-
bindService(container,
|
|
51
|
+
bindService(container, AnotherService);
|
|
51
52
|
|
|
52
|
-
const
|
|
53
|
+
const counterService = container.get(CounterService);
|
|
54
|
+
const anotherService = container.get(AnotherService);
|
|
53
55
|
```
|
|
54
56
|
|
|
55
57
|
`bindService` binds a class in singleton scope by default.
|
|
@@ -60,20 +62,20 @@ Use `bindConstant` to bind a value, `bindEntry` to bind under a custom token.
|
|
|
60
62
|
Events are fire-and-forget messages. Any service can emit or subscribe.
|
|
61
63
|
|
|
62
64
|
```ts
|
|
63
|
-
import { OnEvent, WireScope, Inject } from
|
|
65
|
+
import { OnEvent, WireScope, Inject } from "@wirestate/core";
|
|
64
66
|
|
|
65
67
|
@Injectable()
|
|
66
68
|
export class SenderService {
|
|
67
69
|
public constructor(@Inject(WireScope) private scope: WireScope) {}
|
|
68
70
|
|
|
69
71
|
public notify(): void {
|
|
70
|
-
this.scope.emitEvent(
|
|
72
|
+
this.scope.emitEvent("USER_LOGGED_OUT");
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
@Injectable()
|
|
75
77
|
export class ReceiverService {
|
|
76
|
-
@OnEvent(
|
|
78
|
+
@OnEvent("USER_LOGGED_OUT")
|
|
77
79
|
public onLogout(): void {
|
|
78
80
|
// handle logout
|
|
79
81
|
}
|
|
@@ -87,11 +89,11 @@ export class ReceiverService {
|
|
|
87
89
|
Commands are write operations dispatched by token. A single handler is expected per command type.
|
|
88
90
|
|
|
89
91
|
```ts
|
|
90
|
-
import { OnCommand, WireScope, Inject } from
|
|
92
|
+
import { OnCommand, WireScope, Inject } from "@wirestate/core";
|
|
91
93
|
|
|
92
94
|
@Injectable()
|
|
93
95
|
export class AuthService {
|
|
94
|
-
@OnCommand(
|
|
96
|
+
@OnCommand("LOGIN")
|
|
95
97
|
public async onLogin(payload: { username: string }): Promise<void> {
|
|
96
98
|
// perform login
|
|
97
99
|
}
|
|
@@ -102,7 +104,7 @@ export class AnotherService {
|
|
|
102
104
|
public constructor(@Inject(WireScope) private scope: WireScope) {}
|
|
103
105
|
|
|
104
106
|
public async login(): Promise<void> {
|
|
105
|
-
await this.scope.executeCommand(
|
|
107
|
+
await this.scope.executeCommand("LOGIN").task;
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
```
|
|
@@ -114,13 +116,13 @@ Use `commandOptional` when a handler may not be registered — returns `null` in
|
|
|
114
116
|
Queries are request-response operations. A single handler is expected per query type.
|
|
115
117
|
|
|
116
118
|
```ts
|
|
117
|
-
import { OnQuery, WireScope, Inject } from
|
|
119
|
+
import { OnQuery, WireScope, Inject } from "@wirestate/core";
|
|
118
120
|
|
|
119
121
|
@Injectable()
|
|
120
122
|
export class StoreService {
|
|
121
123
|
private items: Array<string> = [];
|
|
122
124
|
|
|
123
|
-
@OnQuery(
|
|
125
|
+
@OnQuery("STORE_ITEMS")
|
|
124
126
|
public onGetItems(): Array<string> {
|
|
125
127
|
return this.items;
|
|
126
128
|
}
|
|
@@ -131,8 +133,8 @@ export class AnotherService {
|
|
|
131
133
|
public constructor(@Inject(WireScope) private scope: WireScope) {}
|
|
132
134
|
|
|
133
135
|
public async someActionRequiringItems(): Promise<void> {
|
|
134
|
-
const asyncItems: Array<string> = await this.scope.queryData(
|
|
135
|
-
const syncItems: Array<string> = await this.scope.queryData(
|
|
136
|
+
const asyncItems: Array<string> = await this.scope.queryData("STORE_ITEMS");
|
|
137
|
+
const syncItems: Array<string> = await this.scope.queryData("STORE_ITEMS");
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
```
|
|
@@ -142,7 +144,7 @@ export class AnotherService {
|
|
|
142
144
|
Seeds pass initial data to services when they are activated.
|
|
143
145
|
|
|
144
146
|
```ts
|
|
145
|
-
import { SEED, Injectable, Inject } from
|
|
147
|
+
import { SEED, Injectable, Inject } from "@wirestate/core";
|
|
146
148
|
|
|
147
149
|
// Shared seed — same object injected into all services in the tree:
|
|
148
150
|
@Injectable()
|
|
@@ -165,7 +167,7 @@ In React, pass them as `seed` or `seeds` props to the provider — see `@wiresta
|
|
|
165
167
|
## Lifecycle
|
|
166
168
|
|
|
167
169
|
```ts
|
|
168
|
-
import { OnActivated, OnDeactivation } from
|
|
170
|
+
import { OnActivated, OnDeactivation } from "@wirestate/core";
|
|
169
171
|
|
|
170
172
|
@Injectable()
|
|
171
173
|
export class PollingService {
|
|
@@ -173,7 +175,7 @@ export class PollingService {
|
|
|
173
175
|
|
|
174
176
|
@OnActivated()
|
|
175
177
|
public onActivated(): void {
|
|
176
|
-
this.timer = setInterval(() => console.info(
|
|
178
|
+
this.timer = setInterval(() => console.info("interval execution"), 5000);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
@OnDeactivation()
|
|
@@ -190,14 +192,23 @@ export class PollingService {
|
|
|
190
192
|
|
|
191
193
|
`WireScope` is injected per-service and exposes:
|
|
192
194
|
|
|
193
|
-
| Method
|
|
194
|
-
|
|
195
|
-
| `getContainer()`
|
|
196
|
-
| `resolve(token)`
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
199
|
-
| `
|
|
200
|
-
| `
|
|
195
|
+
| Method | Description |
|
|
196
|
+
| ----------------------------------------- | --------------------------------------------------------------- |
|
|
197
|
+
| `getContainer()` | Access the raw IoC container |
|
|
198
|
+
| `resolve(token)` | Resolve a service or value by token |
|
|
199
|
+
| `resolveOptional(token)` | Resolve a service or value, returns `null` if not bound |
|
|
200
|
+
| `getSeed(token?)` | Get the per-service or shared seed |
|
|
201
|
+
| `emitEvent(type, payload?, from?)` | Emit an event |
|
|
202
|
+
| `subscribeToEvent(handler)` | Subscribe a handler to all events; returns unsubscribe function |
|
|
203
|
+
| `unsubscribeFromEvent(handler)` | Remove a specific event subscription by handler reference |
|
|
204
|
+
| `queryData(type, data?)` | Dispatch a query and return the result |
|
|
205
|
+
| `queryOptionalData(type, data?)` | Dispatch a query; returns `null` if no handler is registered |
|
|
206
|
+
| `registerQueryHandler(type, handler)` | Register a query handler; returns unregister function |
|
|
207
|
+
| `unregisterQueryHandler(type, handler)` | Remove a specific query handler by type and reference |
|
|
208
|
+
| `executeCommand(type, data?)` | Dispatch a command and return a descriptor |
|
|
209
|
+
| `executeOptionalCommand(type, data?)` | Dispatch a command; returns `null` if no handler is registered |
|
|
210
|
+
| `registerCommandHandler(type, handler)` | Register a command handler; returns unregister function |
|
|
211
|
+
| `unregisterCommandHandler(type, handler)` | Remove a specific command handler by type and reference |
|
|
201
212
|
|
|
202
213
|
## Test utilities
|
|
203
214
|
|
|
@@ -210,18 +221,18 @@ import {
|
|
|
210
221
|
mockBindService,
|
|
211
222
|
mockBindEntry,
|
|
212
223
|
mockUnbindService,
|
|
213
|
-
} from
|
|
224
|
+
} from "@wirestate/core/test-utils";
|
|
214
225
|
```
|
|
215
226
|
|
|
216
227
|
### `mockContainer(options?)`
|
|
217
228
|
|
|
218
229
|
Creates a configured IoC container for testing. Accepts an optional object:
|
|
219
230
|
|
|
220
|
-
| Option
|
|
221
|
-
|
|
222
|
-
| `entries`
|
|
223
|
-
| `activate`
|
|
224
|
-
| `skipLifecycle` | `boolean`
|
|
231
|
+
| Option | Type | Description |
|
|
232
|
+
| --------------- | ---------------------------------------- | --------------------------------------------- |
|
|
233
|
+
| `entries` | `Array<Newable \| InjectableDescriptor>` | Services or descriptors to bind |
|
|
234
|
+
| `activate` | `Array<ServiceIdentifier>` | Tokens to resolve immediately after binding |
|
|
235
|
+
| `skipLifecycle` | `boolean` | Skip `@OnActivated` / `@OnDeactivation` hooks |
|
|
225
236
|
|
|
226
237
|
```ts
|
|
227
238
|
const container = mockContainer({
|