@mantaq/sugar 0.2.0 → 0.3.0
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/README.md +23 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.mjs +15 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -307,6 +307,29 @@ broadcast(map, { type: "ping" });
|
|
|
307
307
|
|
|
308
308
|
Works with `ActorMap` or any object implementing `{ keys(): string[]; send(key, event): void }`.
|
|
309
309
|
|
|
310
|
+
### `onOutput(actor, handler)`
|
|
311
|
+
|
|
312
|
+
Route an actor's emitted outputs to a handler. `regions` auto-wire child
|
|
313
|
+
outputs into the parent; ActorMap children do not — this is the public
|
|
314
|
+
wrapper for that wiring seam, no internal import needed:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
import { ActorMap, onOutput } from "@mantaq/sugar";
|
|
318
|
+
|
|
319
|
+
const requests = new ActorMap(
|
|
320
|
+
(id) => {
|
|
321
|
+
const child = createHandler(id);
|
|
322
|
+
onOutput(child, (e) => {
|
|
323
|
+
if (result.is(e)) parent.send(e);
|
|
324
|
+
});
|
|
325
|
+
return child;
|
|
326
|
+
},
|
|
327
|
+
{ autoReap: true },
|
|
328
|
+
);
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
The `is()` guard narrows the output to the receiver's declared input.
|
|
332
|
+
|
|
310
333
|
### `tag(...stateRefs)`
|
|
311
334
|
|
|
312
335
|
Group multiple `StateRef`s and test if a snapshot matches any of them. Useful for UI state grouping.
|
package/dist/index.d.mts
CHANGED
|
@@ -60,6 +60,16 @@ declare function states<const T extends StatesArg[]>(...entries: T): StatesRecor
|
|
|
60
60
|
//#region src/event.d.ts
|
|
61
61
|
declare function events<T extends string>(...names: T[]): { [K in T]: EventRef<K>; };
|
|
62
62
|
//#endregion
|
|
63
|
+
//#region src/output.d.ts
|
|
64
|
+
/**
|
|
65
|
+
* Route an actor's emitted outputs to a handler.
|
|
66
|
+
*
|
|
67
|
+
* `regions` auto-wire child outputs into the parent. ActorMap children do
|
|
68
|
+
* not — this is the public wrapper for that wiring seam. One call in the
|
|
69
|
+
* factory connects a child's declared outputs to a receiver.
|
|
70
|
+
*/
|
|
71
|
+
declare function onOutput(actor: AnyActor, handler: (event: InternalEvent) => void): void;
|
|
72
|
+
//#endregion
|
|
63
73
|
//#region src/effects/promise.d.ts
|
|
64
74
|
type EmitFn = (event: {
|
|
65
75
|
type: string;
|
|
@@ -89,4 +99,4 @@ declare function tag(...stateNames: StateRef<string, unknown>[]): Tag;
|
|
|
89
99
|
declare function isIn(snapshot: Snapshot, stateRefName: string): boolean;
|
|
90
100
|
declare function activeLeaves(snapshot: Snapshot): string[];
|
|
91
101
|
//#endregion
|
|
92
|
-
export { ActorMap, type EventLike, type SendableEvent, type SendableMap, activeLeaves, broadcast, events, isIn, matches, states, tag, withPromise, withTimeout };
|
|
102
|
+
export { ActorMap, type EventLike, type SendableEvent, type SendableMap, activeLeaves, broadcast, events, isIn, matches, onOutput, states, tag, withPromise, withTimeout };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { abortEffects } from "@mantaq/core/internal";
|
|
1
|
+
import { abortEffects, setOutputHandler } from "@mantaq/core/internal";
|
|
2
2
|
import { Either } from "@mantaq/utils";
|
|
3
3
|
import { event, state } from "@mantaq/core";
|
|
4
4
|
//#region src/actors/matches.ts
|
|
@@ -45,6 +45,7 @@ var ActorMap = class {
|
|
|
45
45
|
}
|
|
46
46
|
const off = child.on("done", () => {
|
|
47
47
|
if (this.#actors.get(key) === child) this.#actors.delete(key);
|
|
48
|
+
this.#reapers.delete(key);
|
|
48
49
|
});
|
|
49
50
|
this.#reapers.set(key, off);
|
|
50
51
|
}
|
|
@@ -96,6 +97,18 @@ function events(...names) {
|
|
|
96
97
|
return result;
|
|
97
98
|
}
|
|
98
99
|
//#endregion
|
|
100
|
+
//#region src/output.ts
|
|
101
|
+
/**
|
|
102
|
+
* Route an actor's emitted outputs to a handler.
|
|
103
|
+
*
|
|
104
|
+
* `regions` auto-wire child outputs into the parent. ActorMap children do
|
|
105
|
+
* not — this is the public wrapper for that wiring seam. One call in the
|
|
106
|
+
* factory connects a child's declared outputs to a receiver.
|
|
107
|
+
*/
|
|
108
|
+
function onOutput(actor, handler) {
|
|
109
|
+
setOutputHandler(actor, handler);
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
99
112
|
//#region src/effects/promise.ts
|
|
100
113
|
function withPromise(promise, signal, emit, events) {
|
|
101
114
|
promise.then((data) => {
|
|
@@ -137,4 +150,4 @@ function tag(...stateNames) {
|
|
|
137
150
|
return { has: (snapshot) => names.some((name) => isIn(snapshot, name)) };
|
|
138
151
|
}
|
|
139
152
|
//#endregion
|
|
140
|
-
export { ActorMap, activeLeaves, broadcast, events, isIn, matches, states, tag, withPromise, withTimeout };
|
|
153
|
+
export { ActorMap, activeLeaves, broadcast, events, isIn, matches, onOutput, states, tag, withPromise, withTimeout };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantaq/sugar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Userland sugar for mantaq actors — matches, effect helpers, transition utilities.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mantaq/
|
|
24
|
-
"@mantaq/
|
|
23
|
+
"@mantaq/utils": "0.0.2",
|
|
24
|
+
"@mantaq/core": "0.2.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@stryker-mutator/core": "^9",
|