@koordinates/xstate-tree 5.3.0 → 5.4.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 +12 -4
- package/package.json +1 -1
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -410,6 +410,7 @@ declare type RootOptions<TInput> = {
|
|
|
410
410
|
basePath: string;
|
|
411
411
|
getPathName?: () => string;
|
|
412
412
|
getQueryString?: () => string;
|
|
413
|
+
shouldBlockActiveRouteUpdate?: (event: RoutingEvent<any>) => boolean;
|
|
413
414
|
} | undefined;
|
|
414
415
|
input: IsUnknown<TInput> extends true ? undefined : TInput;
|
|
415
416
|
};
|
package/lib/xstateTree.js
CHANGED
|
@@ -331,8 +331,12 @@ function buildRootComponent(options) {
|
|
|
331
331
|
const queryString = getQueryString();
|
|
332
332
|
const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, getPathName(), getQueryString(), initialMeta);
|
|
333
333
|
if (result) {
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
const matchedEvent = result.events[result.events.length - 1];
|
|
335
|
+
const block = routing.shouldBlockActiveRouteUpdate?.(matchedEvent) === true;
|
|
336
|
+
if (!block) {
|
|
337
|
+
setActiveRouteEvents(result.events);
|
|
338
|
+
setActiveRoute({ ...result.matchedRoute });
|
|
339
|
+
}
|
|
336
340
|
}
|
|
337
341
|
// Hack to ensure the initial location doesn't have undefined state
|
|
338
342
|
// It's not supposed to, but it does for some reason
|
|
@@ -347,8 +351,12 @@ function buildRootComponent(options) {
|
|
|
347
351
|
const unsub = routing.history.listen((location) => {
|
|
348
352
|
const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, location.pathname, location.search, location.state?.meta);
|
|
349
353
|
if (result) {
|
|
350
|
-
|
|
351
|
-
|
|
354
|
+
const matchedEvent = result.events[result.events.length - 1];
|
|
355
|
+
const block = routing.shouldBlockActiveRouteUpdate?.(matchedEvent) === true;
|
|
356
|
+
if (!block) {
|
|
357
|
+
setActiveRouteEvents(result.events);
|
|
358
|
+
setActiveRoute({ ...result.matchedRoute });
|
|
359
|
+
}
|
|
352
360
|
}
|
|
353
361
|
});
|
|
354
362
|
return () => {
|
package/package.json
CHANGED