@koordinates/xstate-tree 2.0.1 → 2.0.3

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.
@@ -30,18 +30,14 @@ export function handleLocationChange(routes, basePath, path, search, setActiveRo
30
30
  route = route.parent;
31
31
  }
32
32
  setActiveRouteEvents([...routingEvents, match.event]);
33
- // Bumps the processing for the state machines to the next event tick
34
- // and out of the popstate handler
35
- setTimeout(() => {
36
- while (routingEvents.length > 0) {
37
- const event = routingEvents.pop();
38
- // copy the originalUrl to all parent events
39
- event.originalUrl = match.event.originalUrl;
40
- // @ts-ignore the event won't match GlobalEvents
41
- broadcast(event);
42
- }
33
+ while (routingEvents.length > 0) {
34
+ const event = routingEvents.pop();
35
+ // copy the originalUrl to all parent events
36
+ event.originalUrl = match.event.originalUrl;
43
37
  // @ts-ignore the event won't match GlobalEvents
44
- broadcast(matchedEvent);
45
- }, 0);
38
+ broadcast(event);
39
+ }
40
+ // @ts-ignore the event won't match GlobalEvents
41
+ broadcast(matchedEvent);
46
42
  }
47
43
  }
@@ -8,11 +8,12 @@ function useRoutingContext() {
8
8
  return context;
9
9
  }
10
10
  export function useActiveRouteEvents() {
11
+ var _a;
11
12
  try {
12
13
  const context = useRoutingContext();
13
- return context.activeRouteEvents;
14
+ return (_a = context.activeRouteEvents) === null || _a === void 0 ? void 0 : _a.current;
14
15
  }
15
- catch (_a) {
16
+ catch (_b) {
16
17
  return undefined;
17
18
  }
18
19
  }
package/lib/xstateTree.js CHANGED
@@ -149,8 +149,11 @@ export function buildRootComponent(machine, routing) {
149
149
  }
150
150
  const RootComponent = function XstateTreeRootComponent() {
151
151
  const [_, __, interpreter] = useMachine(machine, { devTools: true });
152
- const [activeRouteEvents, setActiveRouteEvents] = useState(undefined);
152
+ const activeRouteEventsRef = useRef([]);
153
153
  const [forceRenderValue, forceRender] = useState(false);
154
+ const setActiveRouteEvents = (events) => {
155
+ activeRouteEventsRef.current = events;
156
+ };
154
157
  useEffect(() => {
155
158
  function handler(event) {
156
159
  recursivelySend(interpreter, event);
@@ -188,9 +191,9 @@ export function buildRootComponent(machine, routing) {
188
191
  return null;
189
192
  }
190
193
  return {
191
- activeRouteEvents,
194
+ activeRouteEvents: activeRouteEventsRef,
192
195
  };
193
- }, [activeRouteEvents]);
196
+ }, []);
194
197
  if (!interpreter.initialized) {
195
198
  setTimeout(() => forceRender(!forceRenderValue), 0);
196
199
  return null;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "2.0.1",
5
+ "version": "2.0.3",
6
6
  "dependencies": {
7
7
  "@xstate/react": "3.0.0",
8
8
  "fast-memoize": "2.5.2",