@koordinates/xstate-tree 1.0.0-beta.4 → 1.1.0-beta.1

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/utils.js CHANGED
@@ -20,3 +20,11 @@ export function assert(value, msg) {
20
20
  throw new Error("assertion failed");
21
21
  }
22
22
  }
23
+ export function isLikelyPageLoad() {
24
+ // without performance API, we can't tell if this is a page load
25
+ if (typeof performance === "undefined") {
26
+ return false;
27
+ }
28
+ // if it's been < 5 seconds since the page was loaded, it's probably a page load
29
+ return performance.now() < 5000;
30
+ }
@@ -515,6 +515,10 @@ export declare type SharedMeta = {
515
515
  * If true, use history.replace instead history.push
516
516
  */
517
517
  replace?: boolean;
518
+ /**
519
+ * true if the event was triggered by the initial match of the URL on load
520
+ */
521
+ onloadEvent?: boolean;
518
522
  };
519
523
 
520
524
  /**
package/lib/xstateTree.js CHANGED
@@ -7,6 +7,7 @@ import { handleLocationChange, RoutingContext, } from "./routing";
7
7
  import { useActiveRouteEvents } from "./routing/providers";
8
8
  import { useConstant } from "./useConstant";
9
9
  import { useService } from "./useService";
10
+ import { isLikelyPageLoad } from "./utils";
10
11
  export const emitter = new TinyEmitter();
11
12
  /**
12
13
  * @public
@@ -163,7 +164,7 @@ export function buildRootComponent(machine, routing) {
163
164
  if (routing) {
164
165
  const { getPathName = () => window.location.pathname, getQueryString = () => window.location.search, } = routing;
165
166
  const queryString = getQueryString();
166
- handleLocationChange(routing.routes, routing.basePath, getPathName(), getQueryString(), setActiveRouteEvents);
167
+ handleLocationChange(routing.routes, routing.basePath, getPathName(), getQueryString(), setActiveRouteEvents, { onloadEvent: isLikelyPageLoad() });
167
168
  // Hack to ensure the initial location doesn't have undefined state
168
169
  // It's not supposed to, but it does for some reason
169
170
  // And the history library ignores popstate events with undefined state
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": "1.0.0-beta.4",
5
+ "version": "1.1.0-beta.1",
6
6
  "dependencies": {
7
7
  "@xstate/react": "3.0.0",
8
8
  "fast-memoize": "2.5.2",
@@ -15,7 +15,6 @@
15
15
  "rxjs": "6.6.2",
16
16
  "tiny-emitter": "2.1.0",
17
17
  "typescript": "4.7.3",
18
- "xstate": "4.32.0",
19
18
  "zod": "3.17.3"
20
19
  },
21
20
  "devDependencies": {
@@ -43,7 +42,11 @@
43
42
  "jest-environment-jsdom": "28.0.1",
44
43
  "rimraf": "3.0.2",
45
44
  "semantic-release": "19.0.3",
46
- "ts-jest": "28.0.5"
45
+ "ts-jest": "28.0.5",
46
+ "xstate": "4.32.0"
47
+ },
48
+ "peerDependencies": {
49
+ "xstate": ">= 4.20 < 5.0.0"
47
50
  },
48
51
  "scripts": {
49
52
  "lint": "eslint 'src/**/*'",