@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
package/dist/player-actor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player-actor.js","sourceRoot":"","sources":["../src/player-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAYL,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GAIlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE9F,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE
|
|
1
|
+
{"version":3,"file":"player-actor.js","sourceRoot":"","sources":["../src/player-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAYL,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GAIlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE9F,OAAO,EAAE,kBAAkB,EAAE,kB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AIG;IACH,OAAO;QACN,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;CACD"}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import type { RouteContext } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Builds a complete URL from a route template and the context of the actor.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* then appends query params and hash
|
|
5
|
+
* The function replaces each `:param` placeholder and each `:param?` placeholder
|
|
6
|
+
* with a value of `context.params`. It then appends the query params and the hash
|
|
7
|
+
* fragment.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* error
|
|
9
|
+
* Every parameter value must be in `context.params`. The function reads no flat
|
|
10
|
+
* context field, and this is deliberate: a placeholder with a spelling error
|
|
11
|
+
* therefore gives a compile-time error, and it does not resolve to `undefined` in
|
|
12
|
+
* silence.
|
|
11
13
|
*
|
|
12
|
-
* @param routeTemplate -
|
|
13
|
-
* `"/settings/:section?"`.
|
|
14
|
-
* @param context -
|
|
15
|
-
*
|
|
16
|
-
* query
|
|
17
|
-
* @returns The
|
|
14
|
+
* @param routeTemplate - The template of the route path, for example
|
|
15
|
+
* `"/profile/:userId"` or `"/settings/:section?"`.
|
|
16
|
+
* @param context - The context object of the actor. Each route parameter must be in
|
|
17
|
+
* `context.params`, because the function reads no flat context field. An absent
|
|
18
|
+
* `query` field builds a URL without a query, exactly like `query: {}`.
|
|
19
|
+
* @returns The complete URL string.
|
|
18
20
|
*
|
|
19
|
-
* @throws {MissingRouteParamError} When a **
|
|
20
|
-
*
|
|
21
|
-
* when
|
|
21
|
+
* @throws {MissingRouteParamError} When a **necessary** `:param` placeholder has no
|
|
22
|
+
* value in the context. The function omits an optional parameter (`:param?`) in
|
|
23
|
+
* silence when its value is absent. Import the class from
|
|
24
|
+
* `@xmachines/play-xstate/errors`.
|
|
22
25
|
*
|
|
23
26
|
* @example
|
|
24
27
|
* ```typescript
|
|
@@ -26,7 +29,7 @@ import type { RouteContext } from "./types.js";
|
|
|
26
29
|
* // → "/user/123?tab=profile#top"
|
|
27
30
|
*
|
|
28
31
|
* buildRouteUrl("/settings/:section?", { params: {}, query: {} });
|
|
29
|
-
* // → "/settings" (optional param
|
|
32
|
+
* // → "/settings" (the optional param is absent, and there is no query string)
|
|
30
33
|
* ```
|
|
31
34
|
*/
|
|
32
35
|
export declare const buildRouteUrl: (routeTemplate: string, context?: RouteContext) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-url.d.ts","sourceRoot":"","sources":["../../src/routing/build-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C
|
|
1
|
+
{"version":3,"file":"build-url.d.ts","sourceRoot":"","sources":["../../src/routing/build-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,aAAa,GACzB,eAAe,MAAM,EACrB,UAAS,YAA4B,KACnC,MAwCF,CAAC"}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { isAbsoluteRoute } from "./derive-route.js";
|
|
2
2
|
import { MissingRouteParamError } from "../errors.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Builds a complete URL from a route template and the context of the actor.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* then appends query params and hash
|
|
6
|
+
* The function replaces each `:param` placeholder and each `:param?` placeholder
|
|
7
|
+
* with a value of `context.params`. It then appends the query params and the hash
|
|
8
|
+
* fragment.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* error
|
|
10
|
+
* Every parameter value must be in `context.params`. The function reads no flat
|
|
11
|
+
* context field, and this is deliberate: a placeholder with a spelling error
|
|
12
|
+
* therefore gives a compile-time error, and it does not resolve to `undefined` in
|
|
13
|
+
* silence.
|
|
12
14
|
*
|
|
13
|
-
* @param routeTemplate -
|
|
14
|
-
* `"/settings/:section?"`.
|
|
15
|
-
* @param context -
|
|
16
|
-
*
|
|
17
|
-
* query
|
|
18
|
-
* @returns The
|
|
15
|
+
* @param routeTemplate - The template of the route path, for example
|
|
16
|
+
* `"/profile/:userId"` or `"/settings/:section?"`.
|
|
17
|
+
* @param context - The context object of the actor. Each route parameter must be in
|
|
18
|
+
* `context.params`, because the function reads no flat context field. An absent
|
|
19
|
+
* `query` field builds a URL without a query, exactly like `query: {}`.
|
|
20
|
+
* @returns The complete URL string.
|
|
19
21
|
*
|
|
20
|
-
* @throws {MissingRouteParamError} When a **
|
|
21
|
-
*
|
|
22
|
-
* when
|
|
22
|
+
* @throws {MissingRouteParamError} When a **necessary** `:param` placeholder has no
|
|
23
|
+
* value in the context. The function omits an optional parameter (`:param?`) in
|
|
24
|
+
* silence when its value is absent. Import the class from
|
|
25
|
+
* `@xmachines/play-xstate/errors`.
|
|
23
26
|
*
|
|
24
27
|
* @example
|
|
25
28
|
* ```typescript
|
|
@@ -27,26 +30,26 @@ import { MissingRouteParamError } from "../errors.js";
|
|
|
27
30
|
* // → "/user/123?tab=profile#top"
|
|
28
31
|
*
|
|
29
32
|
* buildRouteUrl("/settings/:section?", { params: {}, query: {} });
|
|
30
|
-
* // → "/settings" (optional param
|
|
33
|
+
* // → "/settings" (the optional param is absent, and there is no query string)
|
|
31
34
|
* ```
|
|
32
35
|
*/
|
|
33
36
|
export const buildRouteUrl = (routeTemplate, context = { query: {} }) => {
|
|
34
|
-
// A context without a `query` field builds a query
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
// no query
|
|
38
|
-
// play.route
|
|
39
|
-
// context
|
|
40
|
-
// Handle relative
|
|
37
|
+
// A context without a `query` field builds a URL without a query, in the same way
|
|
38
|
+
// as an absent context. The generated play.route transitions assign `query` on
|
|
39
|
+
// every navigation, and the shape of the initial context has no effect on that.
|
|
40
|
+
// Therefore no query goes away here, and a throw prevents nothing. A machine that
|
|
41
|
+
// handles play.route itself and wants the query must assign event.query to its
|
|
42
|
+
// context itself.
|
|
43
|
+
// Handle a relative path and an absolute path
|
|
41
44
|
const basePath = context.basePath || "";
|
|
42
45
|
const isAbsolute = isAbsoluteRoute(routeTemplate);
|
|
43
|
-
// Build base URL
|
|
46
|
+
// Build the base URL
|
|
44
47
|
let url = isAbsolute ? routeTemplate : joinPaths(basePath, routeTemplate);
|
|
45
|
-
// Replace :param with context
|
|
48
|
+
// Replace each :param with a context value
|
|
46
49
|
url = substituteParams(url, context);
|
|
47
|
-
// Append query params
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
+
// Append the query params of the context. The frequent empty `query: {}` passes the
|
|
51
|
+
// key check first. Therefore each recomputation allocates a URLSearchParams object
|
|
52
|
+
// only when it has something to write.
|
|
50
53
|
if (context.query && typeof context.query === "object") {
|
|
51
54
|
const queryEntries = Object.entries(context.query);
|
|
52
55
|
if (queryEntries.length > 0) {
|
|
@@ -57,75 +60,75 @@ export const buildRouteUrl = (routeTemplate, context = { query: {} }) => {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
|
-
// Append hash
|
|
63
|
+
// Append the hash of the context
|
|
61
64
|
if (context.hash && typeof context.hash === "string") {
|
|
62
65
|
url += `#${context.hash}`;
|
|
63
66
|
}
|
|
64
67
|
return url;
|
|
65
68
|
};
|
|
66
69
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
70
|
+
* Replaces each `:param` placeholder with a context value, and it escapes that
|
|
71
|
+
* value with `encodeURIComponent`.
|
|
69
72
|
*
|
|
70
|
-
*
|
|
71
|
-
* -
|
|
72
|
-
* -
|
|
73
|
+
* The function supports an optional parameter, in the form :param?.
|
|
74
|
+
* - It removes an optional parameter without a value completely, and it also removes the /
|
|
75
|
+
* - It writes a warning for a necessary parameter without a value
|
|
73
76
|
*
|
|
74
|
-
*
|
|
75
|
-
* -
|
|
77
|
+
* The lookup of a parameter:
|
|
78
|
+
* - The function reads context.params[param] only. It reads no flat context field.
|
|
76
79
|
*
|
|
77
|
-
* @param template - URL template with :param or :param? syntax
|
|
78
|
-
* @param context -
|
|
79
|
-
* @returns URL with parameters
|
|
80
|
-
* @throws {MissingRouteParamError} When a
|
|
80
|
+
* @param template - The URL template, with the :param or :param? syntax
|
|
81
|
+
* @param context - The context with the parameter values. It can have a params field
|
|
82
|
+
* @returns The URL with the parameters in place, and without a double slash
|
|
83
|
+
* @throws {MissingRouteParamError} When a necessary route parameter is absent
|
|
81
84
|
*/
|
|
82
85
|
const substituteParams = (template, context) => {
|
|
83
|
-
// Replace
|
|
86
|
+
// Replace each parameter, and handle the optional syntax
|
|
84
87
|
let hasOptionalRemoval = false;
|
|
85
88
|
const result = template.replace(/:(\w+)(\?)?/g, (_match, param, optional) => {
|
|
86
89
|
const value = context.params?.[param]; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
87
|
-
//
|
|
88
|
-
// For optional
|
|
90
|
+
// The parameter has a value that is not empty: put it in place.
|
|
91
|
+
// For an optional param, an empty string means "no value".
|
|
89
92
|
if (value !== undefined && value !== null && value !== "") {
|
|
90
93
|
return encodeURIComponent(String(value));
|
|
91
94
|
}
|
|
92
|
-
//
|
|
95
|
+
// An optional parameter without a value, or with an empty string: remove the segment
|
|
93
96
|
if (optional === "?") {
|
|
94
97
|
hasOptionalRemoval = true;
|
|
95
|
-
return ""; //
|
|
98
|
+
return ""; // This leaves // in the path. The code below removes it
|
|
96
99
|
}
|
|
97
100
|
throw new MissingRouteParamError(param, template);
|
|
98
101
|
});
|
|
99
|
-
//
|
|
102
|
+
// Remove each double slash
|
|
100
103
|
let cleaned = result.replace(/\/+/g, "/");
|
|
101
|
-
//
|
|
102
|
-
//
|
|
104
|
+
// Remove a trailing slash only after the code removed an optional parameter.
|
|
105
|
+
// A trailing slash of a necessary param stays, because it shows an error.
|
|
103
106
|
if (hasOptionalRemoval && cleaned.endsWith("/")) {
|
|
104
107
|
cleaned = cleaned.slice(0, -1);
|
|
105
108
|
}
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
+
// Return an empty path never: a template of the root level with optional params
|
|
110
|
+
// only, for example "/:section?", becomes "" after the trim of the trailing slash.
|
|
111
|
+
// That value makes an invalid URL, such as "" or "?tab=x". Normalize it to "/".
|
|
109
112
|
if (cleaned === "") {
|
|
110
113
|
cleaned = "/";
|
|
111
114
|
}
|
|
112
115
|
return cleaned;
|
|
113
116
|
};
|
|
114
117
|
/**
|
|
115
|
-
*
|
|
118
|
+
* Joins a base path and a relative path
|
|
116
119
|
*
|
|
117
|
-
*
|
|
120
|
+
* The function puts one slash between the two paths
|
|
118
121
|
*
|
|
119
|
-
* @param base -
|
|
120
|
-
* @param relative -
|
|
121
|
-
* @returns
|
|
122
|
+
* @param base - The base path
|
|
123
|
+
* @param relative - The relative path
|
|
124
|
+
* @returns The joined path
|
|
122
125
|
*/
|
|
123
126
|
const joinPaths = (base, relative) => {
|
|
124
|
-
// Remove trailing slash
|
|
127
|
+
// Remove the trailing slash of the base
|
|
125
128
|
const normalizedBase = base.replace(/\/$/, "");
|
|
126
|
-
// Remove
|
|
129
|
+
// Remove the first slash of the relative path
|
|
127
130
|
const normalizedRelative = relative.replace(/^\//, "");
|
|
128
|
-
// Join with
|
|
131
|
+
// Join the two paths with one slash
|
|
129
132
|
return normalizedBase ? `${normalizedBase}/${normalizedRelative}` : `/${normalizedRelative}`;
|
|
130
133
|
};
|
|
131
134
|
//# sourceMappingURL=build-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-url.js","sourceRoot":"","sources":["../../src/routing/build-url.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD
|
|
1
|
+
{"version":3,"file":"build-url.js","sourceRoot":"","sources":["../../src/routing/build-url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AAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACjD,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,gFAAgF;IAChF,mFAAmF;IACnF,gFAAgF;IAChF,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,GAAG,GAAG,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAU,EAAE;IAC5D,wCAAwC;IACxC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAE/C,8CAA8C;IAC9C,MAAM,kBAAkB,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,oCAAoC;IACpC,OAAO,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAAC;AAC9F,CAAC,CAAC"}
|
|
@@ -1,54 +1,60 @@
|
|
|
1
1
|
import type { AnyMachineSnapshot } from "xstate";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Collects the `meta` object of the active state nodes of a SINGLE branch, from the
|
|
4
|
+
* root to a leaf. The key of each entry is the state id, and the order is the
|
|
5
|
+
* ancestors first. {@link deriveRoute} folds this shape.
|
|
5
6
|
*
|
|
6
|
-
* `snapshot.getMeta()` returns a FLAT record of
|
|
7
|
-
*
|
|
8
|
-
* PARALLEL machine it
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* also cannot
|
|
12
|
-
* `id
|
|
13
|
-
* keys are those ids and carry no ancestry
|
|
7
|
+
* `snapshot.getMeta()` returns a FLAT record of the meta object of every active
|
|
8
|
+
* state. For a machine that is not parallel, that record is one chain of ancestors
|
|
9
|
+
* already. For a PARALLEL machine, it mixes the entries of every active region. A
|
|
10
|
+
* blind fold therefore joins a relative route of one region to an absolute route of
|
|
11
|
+
* a sibling region, and the URL belongs to the tree of neither region. The flat
|
|
12
|
+
* record also cannot go back into a hierarchy: when a state declares an explicit
|
|
13
|
+
* `id`, for example a child with `id: "dashboard-overview"` under `id: "dashboard"`,
|
|
14
|
+
* the meta keys are those ids, and they carry no information about the ancestry.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
* by state key
|
|
17
|
-
* each level. This
|
|
18
|
-
*
|
|
19
|
-
* because each node carries its own `id`
|
|
16
|
+
* Therefore this function walks `snapshot.value`, which holds the real hierarchy of
|
|
17
|
+
* the active states by the state key, against the node tree of the machine. It
|
|
18
|
+
* follows the FIRST active child at each level. This gives one deterministic branch,
|
|
19
|
+
* which matches the historical behavior of "the first that it finds" for a parallel
|
|
20
|
+
* machine. It also works with an explicit id, because each node carries its own `id`
|
|
21
|
+
* and its own `meta`.
|
|
20
22
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* The function returns `null` when the snapshot exposes no machine and no value to
|
|
24
|
+
* walk. This is a defensive measure, because a real XState snapshot always exposes
|
|
25
|
+
* them. The caller then uses `getMeta()`, as before.
|
|
23
26
|
*/
|
|
24
27
|
export declare const firstActiveBranchMeta: (snapshot: AnyMachineSnapshot) => Record<string, unknown> | null;
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
27
|
-
* branch {@link firstActiveBranchMeta} walks
|
|
28
|
-
* and explicit
|
|
29
|
-
*
|
|
30
|
-
* `deriveCurrentView`
|
|
31
|
-
*
|
|
29
|
+
* Resolves the meta record that the route derivation and the view derivation fold:
|
|
30
|
+
* the single active branch that {@link firstActiveBranchMeta} walks, which is
|
|
31
|
+
* correct for a parallel machine and for an explicit id, or the flat `getMeta()`
|
|
32
|
+
* record when the snapshot has no machine tree to walk. `deriveCurrentRoute` and
|
|
33
|
+
* `deriveCurrentView` share this function. Therefore the two sides cannot move apart
|
|
34
|
+
* on the selection of the branch, and they cannot move apart on their tolerance of a
|
|
35
|
+
* degenerate snapshot.
|
|
32
36
|
*/
|
|
33
37
|
export declare const activeStateMeta: (snapshot: AnyMachineSnapshot) => Record<string, unknown> | null;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
39
|
+
* Derives the current URL of the actor from the state metadata and the context.
|
|
36
40
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
41
|
+
* The function resolves the route template from the `meta.route` field of the
|
|
42
|
+
* current state. It then replaces each `:param` placeholder with a value of
|
|
43
|
+
* `context.params`, which it prefers, or of the flat `context` object.
|
|
39
44
|
*
|
|
40
|
-
*
|
|
41
|
-
* - The snapshot has no route metadata
|
|
42
|
-
* -
|
|
45
|
+
* The function returns `null`, and it throws no error, in two cases:
|
|
46
|
+
* - The snapshot has no route metadata, which means a state without a route
|
|
47
|
+
* - The context does not hold a necessary route parameter (`MissingRouteParamError`)
|
|
43
48
|
*
|
|
44
|
-
* The `null`
|
|
45
|
-
* stable during
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* stable snapshot
|
|
49
|
+
* The `null` value for an absent param is deliberate: the computed signal therefore
|
|
50
|
+
* stays stable during a temporary state. Such a state appears during a transition,
|
|
51
|
+
* before the context is complete, and also after a logout, when `context.username`
|
|
52
|
+
* is `null` and the router bridge did not reach the new state yet. The router bridge
|
|
53
|
+
* and the URL bar receive the new value on the next stable snapshot, when the
|
|
54
|
+
* context is complete.
|
|
49
55
|
*
|
|
50
|
-
* @param snapshot -
|
|
51
|
-
* @returns
|
|
56
|
+
* @param snapshot - The current snapshot of the XState machine.
|
|
57
|
+
* @returns The resolved URL string, or `null` when the function cannot resolve the route.
|
|
52
58
|
*/
|
|
53
59
|
export declare const deriveCurrentRoute: (snapshot: AnyMachineSnapshot) => string | null;
|
|
54
60
|
//# sourceMappingURL=derive-current-route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-current-route.d.ts","sourceRoot":"","sources":["../../src/routing/derive-current-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAOjD
|
|
1
|
+
{"version":3,"file":"derive-current-route.d.ts","sourceRoot":"","sources":["../../src/routing/derive-current-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAOjD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,qBAAqB,GACjC,UAAU,kBAAkB,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAqC5B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,kBAAkB,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAMxF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,kBAAkB,KAAG,MAAM,GAAG,IA8B1E,CAAC"}
|
|
@@ -2,26 +2,29 @@ import { MissingRouteParamError } from "../errors.js";
|
|
|
2
2
|
import { deriveRoute } from "./derive-route.js";
|
|
3
3
|
import { buildRouteUrl } from "./build-url.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Collects the `meta` object of the active state nodes of a SINGLE branch, from the
|
|
6
|
+
* root to a leaf. The key of each entry is the state id, and the order is the
|
|
7
|
+
* ancestors first. {@link deriveRoute} folds this shape.
|
|
7
8
|
*
|
|
8
|
-
* `snapshot.getMeta()` returns a FLAT record of
|
|
9
|
-
*
|
|
10
|
-
* PARALLEL machine it
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* also cannot
|
|
14
|
-
* `id
|
|
15
|
-
* keys are those ids and carry no ancestry
|
|
9
|
+
* `snapshot.getMeta()` returns a FLAT record of the meta object of every active
|
|
10
|
+
* state. For a machine that is not parallel, that record is one chain of ancestors
|
|
11
|
+
* already. For a PARALLEL machine, it mixes the entries of every active region. A
|
|
12
|
+
* blind fold therefore joins a relative route of one region to an absolute route of
|
|
13
|
+
* a sibling region, and the URL belongs to the tree of neither region. The flat
|
|
14
|
+
* record also cannot go back into a hierarchy: when a state declares an explicit
|
|
15
|
+
* `id`, for example a child with `id: "dashboard-overview"` under `id: "dashboard"`,
|
|
16
|
+
* the meta keys are those ids, and they carry no information about the ancestry.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* by state key
|
|
19
|
-
* each level. This
|
|
20
|
-
*
|
|
21
|
-
* because each node carries its own `id`
|
|
18
|
+
* Therefore this function walks `snapshot.value`, which holds the real hierarchy of
|
|
19
|
+
* the active states by the state key, against the node tree of the machine. It
|
|
20
|
+
* follows the FIRST active child at each level. This gives one deterministic branch,
|
|
21
|
+
* which matches the historical behavior of "the first that it finds" for a parallel
|
|
22
|
+
* machine. It also works with an explicit id, because each node carries its own `id`
|
|
23
|
+
* and its own `meta`.
|
|
22
24
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
* The function returns `null` when the snapshot exposes no machine and no value to
|
|
26
|
+
* walk. This is a defensive measure, because a real XState snapshot always exposes
|
|
27
|
+
* them. The caller then uses `getMeta()`, as before.
|
|
25
28
|
*/
|
|
26
29
|
export const firstActiveBranchMeta = (snapshot) => {
|
|
27
30
|
const root = snapshot.machine?.root;
|
|
@@ -34,9 +37,10 @@ export const firstActiveBranchMeta = (snapshot) => {
|
|
|
34
37
|
if (node.meta && typeof node.meta === "object") {
|
|
35
38
|
ordered[node.id] = node.meta; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
36
39
|
}
|
|
37
|
-
//
|
|
38
|
-
// active leaf
|
|
39
|
-
//
|
|
40
|
+
// Find the key of the active child at this level. A string value is the name of an
|
|
41
|
+
// atomic active leaf. An object value is a compound node, with one key, or a
|
|
42
|
+
// parallel node, with many keys: take the first key, for one deterministic
|
|
43
|
+
// branch.
|
|
40
44
|
let key;
|
|
41
45
|
if (typeof value === "string") {
|
|
42
46
|
key = value;
|
|
@@ -58,12 +62,13 @@ export const firstActiveBranchMeta = (snapshot) => {
|
|
|
58
62
|
return ordered;
|
|
59
63
|
};
|
|
60
64
|
/**
|
|
61
|
-
*
|
|
62
|
-
* branch {@link firstActiveBranchMeta} walks
|
|
63
|
-
* and explicit
|
|
64
|
-
*
|
|
65
|
-
* `deriveCurrentView`
|
|
66
|
-
*
|
|
65
|
+
* Resolves the meta record that the route derivation and the view derivation fold:
|
|
66
|
+
* the single active branch that {@link firstActiveBranchMeta} walks, which is
|
|
67
|
+
* correct for a parallel machine and for an explicit id, or the flat `getMeta()`
|
|
68
|
+
* record when the snapshot has no machine tree to walk. `deriveCurrentRoute` and
|
|
69
|
+
* `deriveCurrentView` share this function. Therefore the two sides cannot move apart
|
|
70
|
+
* on the selection of the branch, and they cannot move apart on their tolerance of a
|
|
71
|
+
* degenerate snapshot.
|
|
67
72
|
*/
|
|
68
73
|
export const activeStateMeta = (snapshot) => {
|
|
69
74
|
if (!snapshot || typeof snapshot.getMeta !== "function") {
|
|
@@ -73,23 +78,25 @@ export const activeStateMeta = (snapshot) => {
|
|
|
73
78
|
return meta && typeof meta === "object" ? meta : null;
|
|
74
79
|
};
|
|
75
80
|
/**
|
|
76
|
-
*
|
|
81
|
+
* Derives the current URL of the actor from the state metadata and the context.
|
|
77
82
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
83
|
+
* The function resolves the route template from the `meta.route` field of the
|
|
84
|
+
* current state. It then replaces each `:param` placeholder with a value of
|
|
85
|
+
* `context.params`, which it prefers, or of the flat `context` object.
|
|
80
86
|
*
|
|
81
|
-
*
|
|
82
|
-
* - The snapshot has no route metadata
|
|
83
|
-
* -
|
|
87
|
+
* The function returns `null`, and it throws no error, in two cases:
|
|
88
|
+
* - The snapshot has no route metadata, which means a state without a route
|
|
89
|
+
* - The context does not hold a necessary route parameter (`MissingRouteParamError`)
|
|
84
90
|
*
|
|
85
|
-
* The `null`
|
|
86
|
-
* stable during
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* stable snapshot
|
|
91
|
+
* The `null` value for an absent param is deliberate: the computed signal therefore
|
|
92
|
+
* stays stable during a temporary state. Such a state appears during a transition,
|
|
93
|
+
* before the context is complete, and also after a logout, when `context.username`
|
|
94
|
+
* is `null` and the router bridge did not reach the new state yet. The router bridge
|
|
95
|
+
* and the URL bar receive the new value on the next stable snapshot, when the
|
|
96
|
+
* context is complete.
|
|
90
97
|
*
|
|
91
|
-
* @param snapshot -
|
|
92
|
-
* @returns
|
|
98
|
+
* @param snapshot - The current snapshot of the XState machine.
|
|
99
|
+
* @returns The resolved URL string, or `null` when the function cannot resolve the route.
|
|
93
100
|
*/
|
|
94
101
|
export const deriveCurrentRoute = (snapshot) => {
|
|
95
102
|
const meta = activeStateMeta(snapshot);
|
|
@@ -104,19 +111,20 @@ export const deriveCurrentRoute = (snapshot) => {
|
|
|
104
111
|
return buildRouteUrl(routeTemplate, (snapshot.context ?? {}));
|
|
105
112
|
}
|
|
106
113
|
catch (error) {
|
|
107
|
-
// MissingRouteParamError:
|
|
108
|
-
// from context during a
|
|
109
|
-
//
|
|
110
|
-
// redirects
|
|
111
|
-
//
|
|
112
|
-
// -
|
|
113
|
-
// -
|
|
114
|
-
//
|
|
115
|
-
//
|
|
114
|
+
// MissingRouteParamError: the condition is temporary, and it resolves itself. A
|
|
115
|
+
// necessary `:param` is absent from the context during a state of a transition, for
|
|
116
|
+
// example an actor in the profile state before the first play.route event fills
|
|
117
|
+
// context.params, and also after a logout, before the bridge redirects. A `null`
|
|
118
|
+
// value is correct here:
|
|
119
|
+
// - a router bridge reads null and skips the navigation (syncRouterFromActor, line 242)
|
|
120
|
+
// - the signal computes its value again on the next snapshot, when the params arrive
|
|
121
|
+
// - a throw goes to each signal watcher as an unhandled exception, for a state
|
|
122
|
+
// that resolves itself. That is worse than a null value for one tick.
|
|
123
|
+
// Do NOT convert this into a throw.
|
|
116
124
|
if (error instanceof MissingRouteParamError) {
|
|
117
125
|
return null;
|
|
118
126
|
}
|
|
119
|
-
//
|
|
127
|
+
// Each unexpected error goes to the caller without a change.
|
|
120
128
|
throw error;
|
|
121
129
|
}
|
|
122
130
|
};
|