@xmachines/play-xstate 2.0.0 → 2.1.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 +66 -65
- package/dist/define-player.d.ts +16 -16
- package/dist/define-player.js +16 -16
- package/dist/errors.d.ts +57 -50
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +63 -55
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +53 -50
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +67 -63
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +22 -22
- package/dist/guards/helpers.js +23 -23
- package/dist/guards/index.d.ts +9 -9
- package/dist/guards/index.js +9 -9
- package/dist/guards/types.d.ts +9 -8
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +162 -146
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +269 -241
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +19 -16
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +62 -59
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +42 -36
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +57 -49
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +23 -20
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +27 -24
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/derive-route.d.ts +38 -37
- package/dist/routing/derive-route.d.ts.map +1 -1
- package/dist/routing/derive-route.js +45 -42
- package/dist/routing/derive-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +34 -28
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +32 -28
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +3 -3
- package/dist/routing/index.js +3 -3
- package/dist/routing/types.d.ts +12 -11
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/types.d.ts +64 -60
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +42 -40
- package/dist/view/derive-current-view.d.ts.map +1 -1
- package/dist/view/derive-current-view.js +51 -47
- package/dist/view/derive-current-view.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { composePlayState, toAtomState } from "@xmachines/play-actor";
|
|
2
2
|
import { activeStateMeta } from "../routing/index.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The migration warning of the `contextProps` field, which 1.x removed. The code
|
|
5
|
+
* writes it one time for each spec. A meta.view object from a person passes around
|
|
6
|
+
* `typedSpec`, and a spec with the field therefore compiles without an error. But
|
|
7
|
+
* the meaning of the field inverted: it was an allowlist, or an empty filter that
|
|
8
|
+
* projected nothing, and the whole context is the value now. The key is the static
|
|
9
|
+
* meta.view object. Therefore the warning appears one time, and not for each
|
|
10
|
+
* snapshot.
|
|
9
11
|
*/
|
|
10
12
|
const warnedContextProps = new WeakSet();
|
|
11
13
|
const warnRemovedContextProps = (viewMeta) => {
|
|
@@ -16,12 +18,12 @@ const warnRemovedContextProps = (viewMeta) => {
|
|
|
16
18
|
"is always projected under /context. Delete the field — it no longer filters anything.");
|
|
17
19
|
};
|
|
18
20
|
const resolveViewMeta = (meta) => {
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
21
|
+
// Walk from the last entry to the first: snapshot.getMeta() puts the keys of the
|
|
22
|
+
// ancestors first. A scan from the end therefore lets the meta.view of the deepest
|
|
23
|
+
// active state win, and an ancestor hides it not.
|
|
22
24
|
const entries = Object.entries(meta);
|
|
23
25
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
24
|
-
//
|
|
26
|
+
// The array index has the bound of the loop. No user controls this property access.
|
|
25
27
|
const [key, stateMeta] = entries[i]; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
26
28
|
const maybeView = stateMeta && typeof stateMeta === "object"
|
|
27
29
|
? stateMeta.view
|
|
@@ -36,54 +38,56 @@ const resolveViewMeta = (meta) => {
|
|
|
36
38
|
return null;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Derives the current view of the actor from the state metadata.
|
|
40
42
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* the UI on every event.
|
|
43
|
+
* The function always returns a **fresh** `PlaySpec` object. The `Object.is`
|
|
44
|
+
* equality test of `Signal.State` therefore stops no real change of the view.
|
|
45
|
+
* `PlayerActor.validateAndCacheView` decides if the actor emits that fresh object:
|
|
46
|
+
* it compares the object with the last spec of an emission, it reuses the reference
|
|
47
|
+
* of the composed `state` field when the value of the projection did not change, and
|
|
48
|
+
* it emits nothing when the view on the screen is the same. A provider below the
|
|
49
|
+
* actor therefore mounts the UI again not on every event.
|
|
48
50
|
*
|
|
49
|
-
* ###
|
|
51
|
+
* ### The context projection
|
|
50
52
|
*
|
|
51
|
-
* The
|
|
52
|
-
* read-only `/context` subtree:
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* the
|
|
53
|
+
* The function projects the context of the machine into the `state` field of the
|
|
54
|
+
* derived spec, under the read-only `/context` subtree:
|
|
55
|
+
* `state: { ...meta.view.state, context: slice }`. The spec of the emission is
|
|
56
|
+
* therefore **consistent with itself**, and its `state` field describes the contents
|
|
57
|
+
* of the store correctly. `repeat.statePath: "/context/tasks"`,
|
|
58
|
+
* `visible: { $state: "/context/…" }`, and a `{ $state: "/context/…" }` prop all
|
|
59
|
+
* resolve through the ordinary state grammar. A tool such as `validateSpec` also
|
|
60
|
+
* passes on a derived view, with no special case. Validate the derived view, and not
|
|
61
|
+
* the raw `meta.view`.
|
|
59
62
|
*
|
|
60
|
-
* The
|
|
61
|
-
* never
|
|
63
|
+
* The store always holds the complete context. The function changes the authored
|
|
64
|
+
* `meta.view` object never.
|
|
62
65
|
*
|
|
63
|
-
* ### viewKey
|
|
66
|
+
* ### The viewKey
|
|
64
67
|
*
|
|
65
|
-
* The derived spec carries `viewKey`
|
|
66
|
-
* the
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* The derived spec carries a `viewKey` field. Its value is the key of the meta
|
|
69
|
+
* record, which is the id of the state node, of the entry that this derivation
|
|
70
|
+
* selected. A provider uses it as the key of its store lifecycle: a new key seeds
|
|
71
|
+
* the store again, and the same key refreshes `/context` in place. The value comes
|
|
72
|
+
* from the selected entry, and not from "the id of the active state", because for a
|
|
73
|
+
* parallel machine the branch of the walk and the flat `getMeta()` fallback can
|
|
74
|
+
* select a view of a different region than the leaf of the branch.
|
|
71
75
|
*
|
|
72
|
-
* @param snapshot -
|
|
73
|
-
* @returns
|
|
76
|
+
* @param snapshot - The current snapshot of the XState machine.
|
|
77
|
+
* @returns The derived `PlaySpec`, or `null` when the current state has no view metadata.
|
|
74
78
|
*/
|
|
75
79
|
export const deriveCurrentView = (snapshot) => {
|
|
76
|
-
// Follow the SAME single active branch the route derivation
|
|
77
|
-
//
|
|
78
|
-
//
|
|
80
|
+
// Follow the SAME single active branch as the route derivation. Therefore the view
|
|
81
|
+
// on the screen of a parallel machine belongs to the region of the URL, when that
|
|
82
|
+
// region declares a view.
|
|
79
83
|
const meta = activeStateMeta(snapshot);
|
|
80
84
|
if (!meta) {
|
|
81
85
|
return null;
|
|
82
86
|
}
|
|
83
|
-
// A parallel machine
|
|
84
|
-
// region owns navigation, another owns the shell
|
|
85
|
-
// declares no view, scan the flat record of every active region
|
|
86
|
-
// entry wins
|
|
87
|
+
// A parallel machine can hold its routes and its views in DIFFERENT regions: one
|
|
88
|
+
// region owns the navigation, and another region owns the shell. When the branch of
|
|
89
|
+
// the walk declares no view, scan the flat record of every active region, where the
|
|
90
|
+
// deepest entry wins, before the conclusion that no view is present.
|
|
87
91
|
let resolved = resolveViewMeta(meta);
|
|
88
92
|
if (!resolved) {
|
|
89
93
|
const flatMeta = snapshot.getMeta();
|
|
@@ -98,9 +102,9 @@ export const deriveCurrentView = (snapshot) => {
|
|
|
98
102
|
if ("contextProps" in viewMeta) {
|
|
99
103
|
warnRemovedContextProps(viewMeta);
|
|
100
104
|
}
|
|
101
|
-
// Project the
|
|
102
|
-
// projection
|
|
103
|
-
//
|
|
105
|
+
// Project the complete context under /context. composePlayState skips the
|
|
106
|
+
// projection, the authored state wins, and the code writes a warning in development,
|
|
107
|
+
// when spec.state declares a top-level "context" key already.
|
|
104
108
|
const slice = snapshot.context !== null && typeof snapshot.context === "object"
|
|
105
109
|
? snapshot.context
|
|
106
110
|
: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-current-view.js","sourceRoot":"","sources":["../../src/view/derive-current-view.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAiB,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAStD
|
|
1
|
+
{"version":3,"file":"derive-current-view.js","sourceRoot":"","sources":["../../src/view/derive-current-view.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAiB,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAStD;;;;;;;;GAQG;AACH,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAU,CAAC;AACjD,MAAM,uBAAuB,GAAG,CAAC,QAAgB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
2
2
|
"name": "@xmachines/play-xstate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "XState v5 adapter for Play Architecture",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actor-model",
|
|
@@ -44,19 +44,20 @@
|
|
|
44
44
|
"clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-* node_modules/.vite*",
|
|
45
45
|
"lint": "oxlint .",
|
|
46
46
|
"format": "oxfmt .",
|
|
47
|
-
"test": "vitest"
|
|
47
|
+
"test": "vitest",
|
|
48
|
+
"test:coverage": "vitest run --coverage"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@xmachines/play": "2.
|
|
51
|
-
"@xmachines/play-actor": "2.
|
|
52
|
-
"@xmachines/play-signals": "2.
|
|
51
|
+
"@xmachines/play": "2.1.0",
|
|
52
|
+
"@xmachines/play-actor": "2.1.0",
|
|
53
|
+
"@xmachines/play-signals": "2.1.0",
|
|
53
54
|
"dequal": "^2.0.3"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@testing-library/jest-dom": "^6.9.1",
|
|
57
58
|
"@types/node": "^26.2.0",
|
|
58
59
|
"@xmachines/json-render-core": "^0.20.0-xm.2",
|
|
59
|
-
"@xmachines/play-router": "2.
|
|
60
|
+
"@xmachines/play-router": "2.1.0",
|
|
60
61
|
"oxfmt": "^0.64.0",
|
|
61
62
|
"oxlint": "^1.79.0",
|
|
62
63
|
"typescript": "^5.9.3 || ^6.0.3",
|