@mantaq/core 0.5.1 → 0.5.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.
Files changed (2) hide show
  1. package/README.md +35 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -536,6 +536,41 @@ m.on(idleState, submitEvent, (event, opts) => {
536
536
  });
537
537
  ```
538
538
 
539
+ ### Reading state in a UI
540
+
541
+ `actor.state.name` is the typed state name: a union of your declared states plus `"__error"`. Read it, not `snapshot().path[0]`, which is an untyped `string`.
542
+
543
+ ```ts
544
+ const render = () => show(actor.state.name);
545
+ actor.on("change", { fn: render });
546
+ render();
547
+ ```
548
+
549
+ Two different failures need two different responses:
550
+
551
+ - **Dead machine.** `actor.state.name === "__error"` (details in `snapshot().error`). A handler threw and the actor is terminal. Create a new actor and offer Reload.
552
+ - **Failed state the machine models.** An `error` state reached through a failure event is an ordinary state. Render it like any other state.
553
+
554
+ `recover()` is not for UIs: it breaks determinism. Recreate the actor instead.
555
+
556
+ To bind any actor without naming `Actor`'s five generics, type the binder on the parts it uses:
557
+
558
+ ```ts
559
+ import type { Snapshot } from "@mantaq/core";
560
+
561
+ function bind<
562
+ A extends {
563
+ state: { name: string };
564
+ on(event: "change", options: { fn: () => void }): () => void;
565
+ snapshot(): Snapshot<unknown>;
566
+ },
567
+ >(actor: A, render: (name: A["state"]["name"]) => void): () => void {
568
+ const paint = () => render(actor.state.name);
569
+ paint();
570
+ return actor.on("change", { fn: paint });
571
+ }
572
+ ```
573
+
539
574
  ### Any Handler
540
575
 
541
576
  Use `onAny` to intercept events across all states. Useful for universal error handling, cleanup, or logging.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantaq/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "State machine runtime with actor model, event system, state hierarchy, effects, and virtual clock.",
5
5
  "license": "MIT",
6
6
  "repository": {