@koordinates/xstate-tree 4.3.0 → 4.4.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/builders.js CHANGED
@@ -3,8 +3,9 @@ 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.createXStateTreeMachine = exports.buildXStateTreeMachine = exports.buildView = exports.buildActions = exports.buildSelectors = void 0;
6
+ exports.viewToMachine = exports.createXStateTreeMachine = exports.buildXStateTreeMachine = exports.buildView = exports.buildActions = exports.buildSelectors = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
+ const xstate_1 = require("xstate");
8
9
  /**
9
10
  * @public
10
11
  *
@@ -148,3 +149,17 @@ function createXStateTreeMachine(machine, options) {
148
149
  return machine;
149
150
  }
150
151
  exports.createXStateTreeMachine = createXStateTreeMachine;
152
+ /**
153
+ * @public
154
+ *
155
+ * Simple utility builder to aid in integrating existing React views with xstate-tree
156
+ *
157
+ * @param view - the React view you want to invoke in an xstate machine
158
+ * @returns The view wrapped into an xstate-tree machine, ready to be invoked by other xstate machines or used with `buildRootComponent`
159
+ */
160
+ function viewToMachine(view) {
161
+ return createXStateTreeMachine((0, xstate_1.createMachine)({ initial: "idle", states: { idle: {} } }), {
162
+ View: view,
163
+ });
164
+ }
165
+ exports.viewToMachine = viewToMachine;
@@ -1,5 +1,5 @@
1
1
  import { AnyEventObject } from 'xstate';
2
- import type { AnyFunction } from 'xstate';
2
+ import { AnyFunction } from 'xstate';
3
3
  import { AnyStateMachine } from 'xstate';
4
4
  import { BaseActionObject } from 'xstate';
5
5
  import { ComponentPropsWithRef } from 'react';
@@ -7,7 +7,7 @@ import { ContextFrom } from 'xstate';
7
7
  import { EventFrom } from 'xstate';
8
8
  import { EventObject } from 'xstate';
9
9
  import { History as History_2 } from 'history';
10
- import type { InterpreterFrom } from 'xstate';
10
+ import { InterpreterFrom } from 'xstate';
11
11
  import { JSXElementConstructor } from 'react';
12
12
  import { ParsedQuery } from 'query-string';
13
13
  import { default as React_2 } from 'react';
@@ -835,6 +835,16 @@ export declare type ViewProps<TSelectors, TActions, TSlots extends readonly Slot
835
835
  inState: TMatches;
836
836
  };
837
837
 
838
+ /**
839
+ * @public
840
+ *
841
+ * Simple utility builder to aid in integrating existing React views with xstate-tree
842
+ *
843
+ * @param view - the React view you want to invoke in an xstate machine
844
+ * @returns The view wrapped into an xstate-tree machine, ready to be invoked by other xstate machines or used with `buildRootComponent`
845
+ */
846
+ export declare function viewToMachine(view: () => JSX.Element): AnyXstateTreeMachine;
847
+
838
848
  /**
839
849
  * @public
840
850
  */
package/lib/xstateTree.js CHANGED
@@ -74,6 +74,7 @@ const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
74
74
  (0, react_2.useEffect)(() => {
75
75
  if (activeRouteEvents) {
76
76
  activeRouteEvents.forEach((event) => {
77
+ // @ts-ignore fixed in v5 branch
77
78
  if (interpreter.state.nextEvents.includes(event.type)) {
78
79
  interpreter.send(event);
79
80
  }
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.3.0",
5
+ "version": "4.4.0-beta.1",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [