@xstate/react 4.0.1 → 4.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.
package/README.md CHANGED
@@ -13,14 +13,6 @@ This package contains utilities for using [XState](https://github.com/statelyai/
13
13
  npm i xstate @xstate/react
14
14
  ```
15
15
 
16
- **Via CDN**
17
-
18
- ```html
19
- <script src="https://unpkg.com/@xstate/react/dist/xstate-react.umd.min.js"></script>
20
- ```
21
-
22
- By using the global variable `XStateReact`
23
-
24
16
  2. Import the `useMachine` hook:
25
17
 
26
18
  ```js
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
- import { ActorRefFrom, AnyStateMachine, SnapshotFrom, ActorOptions, AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, StateMachine, AnyActorLogic } from 'xstate';
3
- type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TActor, infer TAction, infer TGuard, infer TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never;
4
- export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?: ActorOptions<TLogic>): {
2
+ import { Actor, ActorOptions, AnyActorLogic, SnapshotFrom } from 'xstate';
3
+ export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, actorOptions?: ActorOptions<TLogic>): {
5
4
  useSelector: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T, compare?: (a: T, b: T) => boolean) => T;
6
- useActorRef: () => ActorRefFrom<TLogic>;
5
+ useActorRef: () => Actor<TLogic>;
7
6
  Provider: (props: {
8
7
  children: React.ReactNode;
9
8
  options?: ActorOptions<TLogic>;
@@ -11,12 +10,6 @@ export declare function createActorContext<TLogic extends AnyActorLogic>(actorLo
11
10
  * @deprecated Use `logic` instead.
12
11
  */
13
12
  machine?: never;
14
- } & (TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends true ? {
15
13
  logic?: TLogic;
16
- } : {
17
- logic: ToMachinesWithProvidedImplementations<TLogic>;
18
- } : {
19
- logic?: TLogic;
20
- })) => React.ReactElement<any, any>;
14
+ }) => React.ReactElement<any, any>;
21
15
  };
22
- export {};
@@ -1,2 +1,2 @@
1
- import { ActorRefFrom, AnyActorLogic, ActorOptions, SnapshotFrom } from 'xstate';
2
- export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): [SnapshotFrom<TLogic>, ActorRefFrom<TLogic>['send'], ActorRefFrom<TLogic>];
1
+ import { Actor, ActorOptions, AnyActorLogic, SnapshotFrom } from 'xstate';
2
+ export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): [SnapshotFrom<TLogic>, Actor<TLogic>['send'], Actor<TLogic>];
@@ -1,3 +1,3 @@
1
- import { AnyActorLogic, AnyActor, ActorRefFrom, ActorOptions, Observer, SnapshotFrom } from 'xstate';
2
- export declare function useIdleActorRef(logic: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor;
3
- export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, options?: ActorOptions<TLogic>, observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)): ActorRefFrom<TLogic>;
1
+ import { Actor, ActorOptions, AnyActorLogic, Observer, SnapshotFrom } from 'xstate';
2
+ export declare function useIdleActorRef<TLogic extends AnyActorLogic>(logic: TLogic, options: Partial<ActorOptions<TLogic>>): Actor<TLogic>;
3
+ export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, options?: ActorOptions<TLogic>, observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)): Actor<TLogic>;
@@ -1,9 +1,5 @@
1
- import { ActorRefFrom, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, ActorOptions, MissingImplementationsError, StateFrom } from 'xstate';
1
+ import { Actor, ActorOptions, AnyStateMachine, StateFrom } from 'xstate';
2
2
  /**
3
3
  * @alias useActor
4
4
  */
5
- export declare function useMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: ActorOptions<TMachine>): [
6
- StateFrom<TMachine>,
7
- ActorRefFrom<TMachine>['send'],
8
- ActorRefFrom<TMachine>
9
- ];
5
+ export declare function useMachine<TMachine extends AnyStateMachine>(machine: TMachine, options?: ActorOptions<TMachine>): [StateFrom<TMachine>, Actor<TMachine>['send'], Actor<TMachine>];
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var shim = require('use-sync-external-store/shim');
7
- var xstate = require('xstate');
8
7
  var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
8
+ var xstate = require('xstate');
9
9
  var withSelector = require('use-sync-external-store/shim/with-selector');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -165,19 +165,22 @@ function shallowEqual(objA, objB) {
165
165
  return true;
166
166
  }
167
167
 
168
- function createActorContext(actorLogic, interpreterOptions) {
168
+ function createActorContext(actorLogic, actorOptions) {
169
169
  const ReactContext = /*#__PURE__*/React__namespace.createContext(null);
170
170
  const OriginalProvider = ReactContext.Provider;
171
171
  function Provider({
172
172
  children,
173
173
  logic: providedLogic = actorLogic,
174
174
  machine,
175
- options: providedOptions = interpreterOptions
175
+ options: providedOptions
176
176
  }) {
177
177
  if (machine) {
178
178
  throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
179
179
  }
180
- const actor = useActorRef(providedLogic, providedOptions);
180
+ const actor = useActorRef(providedLogic, {
181
+ ...actorOptions,
182
+ ...providedOptions
183
+ });
181
184
  return /*#__PURE__*/React__namespace.createElement(OriginalProvider, {
182
185
  value: actor,
183
186
  children
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var shim = require('use-sync-external-store/shim');
7
- var xstate = require('xstate');
8
7
  var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
8
+ var xstate = require('xstate');
9
9
  var withSelector = require('use-sync-external-store/shim/with-selector');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -168,19 +168,22 @@ function shallowEqual(objA, objB) {
168
168
  return true;
169
169
  }
170
170
 
171
- function createActorContext(actorLogic, interpreterOptions) {
171
+ function createActorContext(actorLogic, actorOptions) {
172
172
  const ReactContext = /*#__PURE__*/React__namespace.createContext(null);
173
173
  const OriginalProvider = ReactContext.Provider;
174
174
  function Provider({
175
175
  children,
176
176
  logic: providedLogic = actorLogic,
177
177
  machine,
178
- options: providedOptions = interpreterOptions
178
+ options: providedOptions
179
179
  }) {
180
180
  if (machine) {
181
181
  throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
182
182
  }
183
- const actor = useActorRef(providedLogic, providedOptions);
183
+ const actor = useActorRef(providedLogic, {
184
+ ...actorOptions,
185
+ ...providedOptions
186
+ });
184
187
  return /*#__PURE__*/React__namespace.createElement(OriginalProvider, {
185
188
  value: actor,
186
189
  children
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { useEffect, useState, useCallback } from 'react';
3
3
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
4
- import { toObserver, createActor } from 'xstate';
5
4
  import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
5
+ import { toObserver, createActor } from 'xstate';
6
6
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
7
7
 
8
8
  const forEachActor = (actorRef, callback) => {
@@ -142,19 +142,22 @@ function shallowEqual(objA, objB) {
142
142
  return true;
143
143
  }
144
144
 
145
- function createActorContext(actorLogic, interpreterOptions) {
145
+ function createActorContext(actorLogic, actorOptions) {
146
146
  const ReactContext = /*#__PURE__*/React.createContext(null);
147
147
  const OriginalProvider = ReactContext.Provider;
148
148
  function Provider({
149
149
  children,
150
150
  logic: providedLogic = actorLogic,
151
151
  machine,
152
- options: providedOptions = interpreterOptions
152
+ options: providedOptions
153
153
  }) {
154
154
  if (machine) {
155
155
  throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
156
156
  }
157
- const actor = useActorRef(providedLogic, providedOptions);
157
+ const actor = useActorRef(providedLogic, {
158
+ ...actorOptions,
159
+ ...providedOptions
160
+ });
158
161
  return /*#__PURE__*/React.createElement(OriginalProvider, {
159
162
  value: actor,
160
163
  children
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { useEffect, useState, useCallback } from 'react';
3
3
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
4
- import { toObserver, createActor } from 'xstate';
5
4
  import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
5
+ import { toObserver, createActor } from 'xstate';
6
6
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
7
7
 
8
8
  const forEachActor = (actorRef, callback) => {
@@ -139,19 +139,22 @@ function shallowEqual(objA, objB) {
139
139
  return true;
140
140
  }
141
141
 
142
- function createActorContext(actorLogic, interpreterOptions) {
142
+ function createActorContext(actorLogic, actorOptions) {
143
143
  const ReactContext = /*#__PURE__*/React.createContext(null);
144
144
  const OriginalProvider = ReactContext.Provider;
145
145
  function Provider({
146
146
  children,
147
147
  logic: providedLogic = actorLogic,
148
148
  machine,
149
- options: providedOptions = interpreterOptions
149
+ options: providedOptions
150
150
  }) {
151
151
  if (machine) {
152
152
  throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
153
153
  }
154
- const actor = useActorRef(providedLogic, providedOptions);
154
+ const actor = useActorRef(providedLogic, {
155
+ ...actorOptions,
156
+ ...providedOptions
157
+ });
155
158
  return /*#__PURE__*/React.createElement(OriginalProvider, {
156
159
  value: actor,
157
160
  children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/react",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "XState tools for React",
5
5
  "keywords": [
6
6
  "state",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "peerDependencies": {
57
57
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
58
- "xstate": "^5.1.0"
58
+ "xstate": "^5.5.2"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "xstate": {
@@ -76,6 +76,6 @@
76
76
  "jsdom-global": "^3.0.2",
77
77
  "react": "^18.0.0",
78
78
  "react-dom": "^18.0.0",
79
- "xstate": "5.1.0"
79
+ "xstate": "5.5.2"
80
80
  }
81
81
  }