@koordinates/xstate-tree 4.9.0 → 4.10.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/lib/xstate-tree.d.ts +1 -0
- package/lib/xstateTree.js +14 -6
- package/package.json +1 -1
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -180,6 +180,7 @@ export declare function buildRootComponent(machine: AnyXstateTreeMachine, routin
|
|
|
180
180
|
basePath: string;
|
|
181
181
|
getPathName?: () => string;
|
|
182
182
|
getQueryString?: () => string;
|
|
183
|
+
shouldBlockActiveRouteUpdate?: (event: RoutingEvent<any>) => boolean;
|
|
183
184
|
}): {
|
|
184
185
|
(): JSX.Element | null;
|
|
185
186
|
rootMachine: AnyXstateTreeMachine;
|
package/lib/xstateTree.js
CHANGED
|
@@ -331,7 +331,7 @@ function buildRootComponent(machine, routing) {
|
|
|
331
331
|
};
|
|
332
332
|
}, [activeRoute]);
|
|
333
333
|
(0, react_2.useEffect)(() => {
|
|
334
|
-
var _a, _b;
|
|
334
|
+
var _a, _b, _c;
|
|
335
335
|
if (routing) {
|
|
336
336
|
const { getPathName = () => routing.history.location.pathname, getQueryString = () => routing.history.location.search, } = routing;
|
|
337
337
|
const initialMeta = {
|
|
@@ -341,8 +341,12 @@ function buildRootComponent(machine, routing) {
|
|
|
341
341
|
const queryString = getQueryString();
|
|
342
342
|
const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, getPathName(), getQueryString(), initialMeta);
|
|
343
343
|
if (result) {
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
const matchedEvent = result.events[result.events.length - 1];
|
|
345
|
+
const block = ((_c = routing.shouldBlockActiveRouteUpdate) === null || _c === void 0 ? void 0 : _c.call(routing, matchedEvent)) === true;
|
|
346
|
+
if (!block) {
|
|
347
|
+
setActiveRouteEvents(result.events);
|
|
348
|
+
setActiveRoute({ ...result.matchedRoute });
|
|
349
|
+
}
|
|
346
350
|
}
|
|
347
351
|
// Hack to ensure the initial location doesn't have undefined state
|
|
348
352
|
// It's not supposed to, but it does for some reason
|
|
@@ -355,11 +359,15 @@ function buildRootComponent(machine, routing) {
|
|
|
355
359
|
(0, react_2.useEffect)(() => {
|
|
356
360
|
if (routing) {
|
|
357
361
|
const unsub = routing.history.listen((location) => {
|
|
358
|
-
var _a;
|
|
362
|
+
var _a, _b;
|
|
359
363
|
const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, location.pathname, location.search, (_a = location.state) === null || _a === void 0 ? void 0 : _a.meta);
|
|
360
364
|
if (result) {
|
|
361
|
-
|
|
362
|
-
|
|
365
|
+
const matchedEvent = result.events[result.events.length - 1];
|
|
366
|
+
const block = ((_b = routing.shouldBlockActiveRouteUpdate) === null || _b === void 0 ? void 0 : _b.call(routing, matchedEvent)) === true;
|
|
367
|
+
if (!block) {
|
|
368
|
+
setActiveRouteEvents(result.events);
|
|
369
|
+
setActiveRoute({ ...result.matchedRoute });
|
|
370
|
+
}
|
|
363
371
|
}
|
|
364
372
|
});
|
|
365
373
|
return () => {
|
package/package.json
CHANGED