@koordinates/xstate-tree 4.6.5 → 4.6.6

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useActiveRouteEvents = exports.useInRoutingContext = exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
3
+ exports.useActiveRouteEvents = exports.useInTestRoutingContext = exports.useInRoutingContext = exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
4
4
  var createRoute_1 = require("./createRoute");
5
5
  Object.defineProperty(exports, "buildCreateRoute", { enumerable: true, get: function () { return createRoute_1.buildCreateRoute; } });
6
6
  var joinRoutes_1 = require("./joinRoutes");
@@ -19,4 +19,5 @@ var providers_1 = require("./providers");
19
19
  Object.defineProperty(exports, "RoutingContext", { enumerable: true, get: function () { return providers_1.RoutingContext; } });
20
20
  Object.defineProperty(exports, "TestRoutingContext", { enumerable: true, get: function () { return providers_1.TestRoutingContext; } });
21
21
  Object.defineProperty(exports, "useInRoutingContext", { enumerable: true, get: function () { return providers_1.useInRoutingContext; } });
22
+ Object.defineProperty(exports, "useInTestRoutingContext", { enumerable: true, get: function () { return providers_1.useInTestRoutingContext; } });
22
23
  Object.defineProperty(exports, "useActiveRouteEvents", { enumerable: true, get: function () { return providers_1.useActiveRouteEvents; } });
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TestRoutingContext = exports.useActiveRouteEvents = exports.useInRoutingContext = exports.RoutingContext = void 0;
6
+ exports.TestRoutingContext = exports.useActiveRouteEvents = exports.useInTestRoutingContext = exports.useInRoutingContext = exports.RoutingContext = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const react_2 = require("react");
9
9
  exports.RoutingContext = (0, react_2.createContext)(undefined);
@@ -22,6 +22,15 @@ function useInRoutingContext() {
22
22
  return context !== undefined;
23
23
  }
24
24
  exports.useInRoutingContext = useInRoutingContext;
25
+ /**
26
+ * @private
27
+ */
28
+ function useInTestRoutingContext() {
29
+ var _a;
30
+ const context = (0, react_2.useContext)(exports.RoutingContext);
31
+ return (_a = context === null || context === void 0 ? void 0 : context.isTestRoutingContext) !== null && _a !== void 0 ? _a : false;
32
+ }
33
+ exports.useInTestRoutingContext = useInTestRoutingContext;
25
34
  /**
26
35
  * @public
27
36
  *
@@ -47,6 +56,9 @@ exports.useActiveRouteEvents = useActiveRouteEvents;
47
56
  * @param activeRouteEvents - The active route events to use in the context
48
57
  */
49
58
  function TestRoutingContext({ activeRouteEvents, children, }) {
50
- return (react_1.default.createElement(exports.RoutingContext.Provider, { value: { activeRouteEvents: { current: activeRouteEvents } } }, children));
59
+ return (react_1.default.createElement(exports.RoutingContext.Provider, { value: {
60
+ activeRouteEvents: { current: activeRouteEvents },
61
+ isTestRoutingContext: true,
62
+ } }, children));
51
63
  }
52
64
  exports.TestRoutingContext = TestRoutingContext;
package/lib/xstateTree.js CHANGED
@@ -32,7 +32,6 @@ const fast_memoize_1 = __importDefault(require("fast-memoize"));
32
32
  const react_2 = __importStar(require("react"));
33
33
  const tiny_emitter_1 = require("tiny-emitter");
34
34
  const routing_1 = require("./routing");
35
- const providers_1 = require("./routing/providers");
36
35
  const useConstant_1 = require("./useConstant");
37
36
  const useService_1 = require("./useService");
38
37
  const utils_1 = require("./utils");
@@ -70,7 +69,7 @@ interpreter) {
70
69
  }
71
70
  const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
72
71
  return react_2.default.memo(function InterpreterView() {
73
- const activeRouteEvents = (0, providers_1.useActiveRouteEvents)();
72
+ const activeRouteEvents = (0, routing_1.useActiveRouteEvents)();
74
73
  (0, react_2.useEffect)(() => {
75
74
  if (activeRouteEvents) {
76
75
  activeRouteEvents.forEach((event) => {
@@ -255,7 +254,10 @@ function buildRootComponent(machine, routing) {
255
254
  activeRouteEventsRef.current = events;
256
255
  };
257
256
  const insideRoutingContext = (0, routing_1.useInRoutingContext)();
258
- if (insideRoutingContext && typeof routing !== "undefined") {
257
+ const inTestRoutingContext = (0, routing_1.useInTestRoutingContext)();
258
+ if (!inTestRoutingContext &&
259
+ insideRoutingContext &&
260
+ typeof routing !== "undefined") {
259
261
  const m = "Routing root rendered inside routing context, this implies a bug";
260
262
  if (process.env.NODE_ENV !== "production") {
261
263
  throw new Error(m);
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": "4.6.5",
5
+ "version": "4.6.6",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [