@koordinates/xstate-tree 5.2.0 → 5.2.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.
- package/lib/routing/createRoute/createRoute.js +15 -0
- package/lib/utils.js +30 -1
- package/package.json +1 -1
|
@@ -102,12 +102,27 @@ function buildCreateRoute(history, basePath) {
|
|
|
102
102
|
let url = fullUrl;
|
|
103
103
|
const parentRoutes = getParentArray();
|
|
104
104
|
let params = {};
|
|
105
|
+
const parsedQuery = (0, query_string_1.parse)(search);
|
|
105
106
|
while (parentRoutes.length) {
|
|
106
107
|
const parentRoute = parentRoutes.shift();
|
|
107
108
|
const parentMatch = parentRoute.matcher(url, undefined);
|
|
108
109
|
if (parentMatch === false) {
|
|
109
110
|
return false;
|
|
110
111
|
}
|
|
112
|
+
// Evaluate parent's canMatch predicate if provided
|
|
113
|
+
if (parentRoute.canMatch) {
|
|
114
|
+
const accumulatedParams = {
|
|
115
|
+
...params,
|
|
116
|
+
...(parentMatch.params ?? {}),
|
|
117
|
+
};
|
|
118
|
+
const canMatchResult = parentRoute.canMatch({
|
|
119
|
+
params: accumulatedParams,
|
|
120
|
+
query: parsedQuery,
|
|
121
|
+
});
|
|
122
|
+
if (!canMatchResult) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
111
126
|
url = url.slice(parentMatch.matchLength);
|
|
112
127
|
// All routes assume the url starts with a /
|
|
113
128
|
// so if the parent route matches the / in the url, which consumes it
|
package/lib/utils.js
CHANGED
|
@@ -121,12 +121,35 @@ function mergeMeta(meta) {
|
|
|
121
121
|
}, {});
|
|
122
122
|
}
|
|
123
123
|
exports.mergeMeta = mergeMeta;
|
|
124
|
+
function isReactElement(value) {
|
|
125
|
+
if (typeof value !== "object" || value === null) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const v = value;
|
|
129
|
+
// React elements have $$typeof set to Symbol(react.element) or
|
|
130
|
+
// Symbol(react.transitional.element)
|
|
131
|
+
if (typeof v.$$typeof === "symbol" && String(v.$$typeof).includes("react")) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
124
136
|
function getCircularReplacer(stripKeys) {
|
|
125
137
|
const seen = new WeakSet();
|
|
126
138
|
return (key, value) => {
|
|
127
139
|
if (stripKeys.includes(key)) {
|
|
128
140
|
return;
|
|
129
141
|
}
|
|
142
|
+
// Replace React elements with a placeholder to avoid
|
|
143
|
+
// traversing massive internal fiber structures
|
|
144
|
+
if (isReactElement(value)) {
|
|
145
|
+
const type = value.type;
|
|
146
|
+
const name = typeof type === "string"
|
|
147
|
+
? type
|
|
148
|
+
: typeof type === "function"
|
|
149
|
+
? type.displayName || type.name || "Anonymous"
|
|
150
|
+
: "Unknown";
|
|
151
|
+
return `[React Element: ${name}]`;
|
|
152
|
+
}
|
|
130
153
|
if (typeof value === "object" && value !== null) {
|
|
131
154
|
if (seen.has(value)) {
|
|
132
155
|
// Circular reference found, discard key
|
|
@@ -139,6 +162,12 @@ function getCircularReplacer(stripKeys) {
|
|
|
139
162
|
};
|
|
140
163
|
}
|
|
141
164
|
function toJSON(value, stripKeys = []) {
|
|
142
|
-
|
|
165
|
+
const start = performance.now();
|
|
166
|
+
const result = JSON.parse(JSON.stringify(value, getCircularReplacer(stripKeys)));
|
|
167
|
+
const elapsed = performance.now() - start;
|
|
168
|
+
if (typeof result === "object" && result !== null) {
|
|
169
|
+
result.__toJSON_ms = Math.round(elapsed * 100) / 100;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
143
172
|
}
|
|
144
173
|
exports.toJSON = toJSON;
|
package/package.json
CHANGED