Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xstate/react

Package Overview
Dependencies
Maintainers
3
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xstate/react - npm Package Compare versions

Comparing version 1.6.3 to 2.0.1

64

CHANGELOG.md
# Changelog
## 2.0.1
### Patch Changes
- [#3089](https://github.com/statelyai/xstate/pull/3089) [`862697e29`](https://github.com/statelyai/xstate/commit/862697e2990934d46050580d7e09c749d09d8426) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility with Skypack by exporting some shared utilities from root entry of XState and consuming them directly in other packages (this avoids accessing those things using deep imports and thus it avoids creating those compatibility problems).
## 2.0.0
### Major Changes
- [#2674](https://github.com/statelyai/xstate/pull/2674) [`e5a8b8dff`](https://github.com/statelyai/xstate/commit/e5a8b8dffb88cffbdca26683099ffdf5f1b01c8d) Thanks [@Andarist](https://github.com/Andarist), [@mattpocock](https://github.com/mattpocock)! - To avoid breaking any consumers and to leverage the newly introduced typegen support, the major version of this package had to be bumped. While you can still use it with older versions of TS, the typegen support in this package requires TS version 4.0 or greater.
When using hooks from `@xstate/react` it's recommended to skip providing explicit generics to them. Note that that generics list has changed since v1 and we now only accept a single generic, `TMachine`.
* [#2674](https://github.com/statelyai/xstate/pull/2674) [`ab919d300`](https://github.com/statelyai/xstate/commit/ab919d300f6d2b78871d3399ec58a697c4268d9b) Thanks [@Andarist](https://github.com/Andarist)! - Removed already deprecated `useService` from `@xstate/react`. You can replace its usage with `useActor`.
### Patch Changes
- [#2957](https://github.com/statelyai/xstate/pull/2957) [`8550ddda7`](https://github.com/statelyai/xstate/commit/8550ddda73e2ad291e19173d7fa8d13e3336fbb9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The repository links have been updated from `github.com/davidkpiano` to `github.com/statelyai`.
## 1.6.3

@@ -13,3 +33,3 @@

- [#2736](https://github.com/statelyai/xstate/pull/2736) [`2246ae051`](https://github.com/statelyai/xstate/commit/2246ae051663f261b4750d7adba57f008ec28f1d) Thanks [@Andarist](https://github.com/Andarist), [@davidkpiano](https://github.com/davidkpiano), [@VanTanev](https://github.com/VanTanev)! - The `useSelector(...)` hook now works as expected when the `actor` passed in changes. The hook will properly subscribe to the new `actor` and select the desired value. See [#2702](https://github.com/statelyai/xstate/issues/2702)
- [#2736](https://github.com/statelyai/xstate/pull/2736) [`2246ae051`](https://github.com/statelyai/xstate/commit/2246ae051663f261b4750d7adba57f008ec28f1d) Thanks [@Andarist](https://github.com/Andarist), [@davidkpiano](https://github.com/statelyai), [@VanTanev](https://github.com/VanTanev)! - The `useSelector(...)` hook now works as expected when the `actor` passed in changes. The hook will properly subscribe to the new `actor` and select the desired value. See [#2702](https://github.com/statelyai/xstate/issues/2702)

@@ -110,3 +130,3 @@ * [#2685](https://github.com/statelyai/xstate/pull/2685) [`469268d39`](https://github.com/statelyai/xstate/commit/469268d39fbc23996599773adfc4ca824b48585f) Thanks [@farskid](https://github.com/farskid), [@Andarist](https://github.com/Andarist)! - Fixed a regression with a development-only warning not being shown when a machine reference is updated during the hook lifecycle. This usually happens when machine options are dependent on external values and they're passed via `withConfig`.

- [`453acacb`](https://github.com/statelyai/xstate/commit/453acacbec364531a2851f183c3ab446d7db0e84) [#2389](https://github.com/statelyai/xstate/pull/2389) Thanks [@davidkpiano](https://github.com/davidkpiano)! - An internal issue where the `spawnBehavior` import for the `useSpawn(...)` hook was broken internally has been fixed.
- [`453acacb`](https://github.com/statelyai/xstate/commit/453acacbec364531a2851f183c3ab446d7db0e84) [#2389](https://github.com/statelyai/xstate/pull/2389) Thanks [@davidkpiano](https://github.com/statelyai)! - An internal issue where the `spawnBehavior` import for the `useSpawn(...)` hook was broken internally has been fixed.

@@ -117,3 +137,3 @@ ## 1.5.0

- [`432b60f7`](https://github.com/statelyai/xstate/commit/432b60f7bcbcee9510e0d86311abbfd75b1a674e) [#2280](https://github.com/statelyai/xstate/pull/2280) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Just like `useInvoke(...)`, other types of actors can now be spawned from _behaviors_ using `useSpawn(...)`:
- [`432b60f7`](https://github.com/statelyai/xstate/commit/432b60f7bcbcee9510e0d86311abbfd75b1a674e) [#2280](https://github.com/statelyai/xstate/pull/2280) Thanks [@davidkpiano](https://github.com/statelyai)! - Just like `useInvoke(...)`, other types of actors can now be spawned from _behaviors_ using `useSpawn(...)`:

@@ -172,3 +192,3 @@ ```tsx

- [`849ec56c`](https://github.com/davidkpiano/xstate/commit/849ec56c2a9db34e65a30af94e68a7a7a50b4158) [#2286](https://github.com/davidkpiano/xstate/pull/2286) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `useService(...)` hook will be deprecated, since services are also actors. In future versions, the `useActor(...)` hook should be used instead:
- [`849ec56c`](https://github.com/statelyai/xstate/commit/849ec56c2a9db34e65a30af94e68a7a7a50b4158) [#2286](https://github.com/statelyai/xstate/pull/2286) Thanks [@davidkpiano](https://github.com/statelyai)! - The `useService(...)` hook will be deprecated, since services are also actors. In future versions, the `useActor(...)` hook should be used instead:

@@ -182,3 +202,3 @@ ```diff

- [`ea3aaffb`](https://github.com/davidkpiano/xstate/commit/ea3aaffb906b34a42bb2736c7b91d54ffe9ed882) [#2326](https://github.com/davidkpiano/xstate/pull/2326) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `send` type returned in the tuple from `useActor(someService)` was an incorrect `never` type; this has been fixed.
- [`ea3aaffb`](https://github.com/statelyai/xstate/commit/ea3aaffb906b34a42bb2736c7b91d54ffe9ed882) [#2326](https://github.com/statelyai/xstate/pull/2326) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` type returned in the tuple from `useActor(someService)` was an incorrect `never` type; this has been fixed.

@@ -189,3 +209,3 @@ ## 1.3.4

- [`aa3c2991`](https://github.com/davidkpiano/xstate/commit/aa3c29916b7382fbcf1a3efb183ca1e8eb625480) [#2223](https://github.com/davidkpiano/xstate/pull/2223) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Support for actor refs with the `.getSnapshot()` method (added for spawned actors in XState version 4.19) is now supported in the `useActor(...)` hook.
- [`aa3c2991`](https://github.com/statelyai/xstate/commit/aa3c29916b7382fbcf1a3efb183ca1e8eb625480) [#2223](https://github.com/statelyai/xstate/pull/2223) Thanks [@davidkpiano](https://github.com/statelyai)! - Support for actor refs with the `.getSnapshot()` method (added for spawned actors in XState version 4.19) is now supported in the `useActor(...)` hook.

@@ -196,3 +216,3 @@ ## 1.3.3

- [`27e7242c`](https://github.com/davidkpiano/xstate/commit/27e7242c24146de85cf618a658b400a3241fa7d7) [#2112](https://github.com/davidkpiano/xstate/pull/2112) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `executeEffect` function is no longer exported (was meant to be internal and is useless as a public function anyway). This also fixes a circular dependency issue.
- [`27e7242c`](https://github.com/statelyai/xstate/commit/27e7242c24146de85cf618a658b400a3241fa7d7) [#2112](https://github.com/statelyai/xstate/pull/2112) Thanks [@davidkpiano](https://github.com/statelyai)! - The `executeEffect` function is no longer exported (was meant to be internal and is useless as a public function anyway). This also fixes a circular dependency issue.

@@ -203,3 +223,3 @@ ## 1.3.2

- [`bb5e81ea`](https://github.com/davidkpiano/xstate/commit/bb5e81eaa1ecba1fd54a7677ce9eaee9bd695964) [#2050](https://github.com/davidkpiano/xstate/pull/2050) Thanks [@theKashey](https://github.com/theKashey)! - Added an explicit entrypoint for `@xstate/react/fsm` which you can use instead of `@xstate/react/lib/fsm`. This is the only specifier that will be supported in the future - the other one will be dropped in the next major version.
- [`bb5e81ea`](https://github.com/statelyai/xstate/commit/bb5e81eaa1ecba1fd54a7677ce9eaee9bd695964) [#2050](https://github.com/statelyai/xstate/pull/2050) Thanks [@theKashey](https://github.com/theKashey)! - Added an explicit entrypoint for `@xstate/react/fsm` which you can use instead of `@xstate/react/lib/fsm`. This is the only specifier that will be supported in the future - the other one will be dropped in the next major version.

@@ -215,5 +235,5 @@ ```diff

- [`b076b253`](https://github.com/davidkpiano/xstate/commit/b076b25364224874f62e8065892be40dfbb28030) [#1947](https://github.com/davidkpiano/xstate/pull/1947) Thanks [@lukekarrys](https://github.com/lukekarrys)! - Fix typing of the service returned from the fsm useMachine hook by passing it Typestate
- [`b076b253`](https://github.com/statelyai/xstate/commit/b076b25364224874f62e8065892be40dfbb28030) [#1947](https://github.com/statelyai/xstate/pull/1947) Thanks [@lukekarrys](https://github.com/lukekarrys)! - Fix typing of the service returned from the fsm useMachine hook by passing it Typestate
* [`9b5dc784`](https://github.com/davidkpiano/xstate/commit/9b5dc7843c44f50bcca0ffccb843b3d50cef6ddc) [#1950](https://github.com/davidkpiano/xstate/pull/1950) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `toObserver` being internally imported from `xstate/lib/utils` which has broken UMD build and the declared peer dep contract.
* [`9b5dc784`](https://github.com/statelyai/xstate/commit/9b5dc7843c44f50bcca0ffccb843b3d50cef6ddc) [#1950](https://github.com/statelyai/xstate/pull/1950) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `toObserver` being internally imported from `xstate/lib/utils` which has broken UMD build and the declared peer dep contract.

@@ -224,3 +244,3 @@ ## 1.3.0

- [`577ae023`](https://github.com/davidkpiano/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/davidkpiano/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/davidkpiano)! - New hook: `useInterpret(machine)`, which is a low-level hook that interprets the `machine` and returns the `service`:
- [`577ae023`](https://github.com/statelyai/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/statelyai/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/statelyai)! - New hook: `useInterpret(machine)`, which is a low-level hook that interprets the `machine` and returns the `service`:

@@ -238,3 +258,3 @@ ```js

* [`577ae023`](https://github.com/davidkpiano/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/davidkpiano/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/davidkpiano)! - New hook: `useSelector(actor, selector)`, which subscribes to `actor` and returns the selected state derived from `selector(snapshot)`:
* [`577ae023`](https://github.com/statelyai/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/statelyai/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/statelyai)! - New hook: `useSelector(actor, selector)`, which subscribes to `actor` and returns the selected state derived from `selector(snapshot)`:

@@ -255,3 +275,3 @@ ```js

- [`4b31cefb`](https://github.com/davidkpiano/xstate/commit/4b31cefb3d3497e5515314046639df7e27dbe9e8) [#1780](https://github.com/davidkpiano/xstate/pull/1780) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with some external packages not being bundled correctly into the UMD bundles.
- [`4b31cefb`](https://github.com/statelyai/xstate/commit/4b31cefb3d3497e5515314046639df7e27dbe9e8) [#1780](https://github.com/statelyai/xstate/pull/1780) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with some external packages not being bundled correctly into the UMD bundles.

@@ -262,3 +282,3 @@ ## 1.2.1

- [`a16a5f2f`](https://github.com/davidkpiano/xstate/commit/a16a5f2ff5ba9d4d7834ec3ca2d0adecf5d6a870) [#1756](https://github.com/davidkpiano/xstate/pull/1756) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Fixed an issue with `process` references not being removed correctly from the UMD bundles.
- [`a16a5f2f`](https://github.com/statelyai/xstate/commit/a16a5f2ff5ba9d4d7834ec3ca2d0adecf5d6a870) [#1756](https://github.com/statelyai/xstate/pull/1756) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Fixed an issue with `process` references not being removed correctly from the UMD bundles.

@@ -269,3 +289,3 @@ ## 1.2.0

- [`dd98296e`](https://github.com/davidkpiano/xstate/commit/dd98296e9fcbae905da2395e67e876e28be7c774) [#1738](https://github.com/davidkpiano/xstate/pull/1738) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Added UMD bundle.
- [`dd98296e`](https://github.com/statelyai/xstate/commit/dd98296e9fcbae905da2395e67e876e28be7c774) [#1738](https://github.com/statelyai/xstate/pull/1738) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Added UMD bundle.

@@ -276,3 +296,3 @@ ## 1.1.0

- [`89f9c27c`](https://github.com/davidkpiano/xstate/commit/89f9c27c453dc56bdfdf49c8ea1f0f87ff1f9b67) [#1622](https://github.com/davidkpiano/xstate/pull/1622) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Spawned/invoked actors and interpreters are now typed as extending `ActorRef` rather than `Actor` or `Interpreter`. This unification of types should make it more straightforward to provide actor types in React:
- [`89f9c27c`](https://github.com/statelyai/xstate/commit/89f9c27c453dc56bdfdf49c8ea1f0f87ff1f9b67) [#1622](https://github.com/statelyai/xstate/pull/1622) Thanks [@davidkpiano](https://github.com/statelyai)! - Spawned/invoked actors and interpreters are now typed as extending `ActorRef` rather than `Actor` or `Interpreter`. This unification of types should make it more straightforward to provide actor types in React:

@@ -319,3 +339,3 @@ ```ts

- [`27db2950`](https://github.com/davidkpiano/xstate/commit/27db295064d42cacb89ff10d55f39eb7609148e1) [#1636](https://github.com/davidkpiano/xstate/pull/1636) Thanks [@Andarist](https://github.com/Andarist)! - Allow React 17 in the specified peer dependency range.
- [`27db2950`](https://github.com/statelyai/xstate/commit/27db295064d42cacb89ff10d55f39eb7609148e1) [#1636](https://github.com/statelyai/xstate/pull/1636) Thanks [@Andarist](https://github.com/Andarist)! - Allow React 17 in the specified peer dependency range.

@@ -326,5 +346,5 @@ ## 1.0.2

- [`c7927083`](https://github.com/davidkpiano/xstate/commit/c7927083a651e3c51952ade2ffda793df0391bf6) [#1516](https://github.com/davidkpiano/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `send` function returned from the `useService()` now can take two arguments (an event type and payload), to match the behavior of `@xstate/react` version 0.x.
- [`c7927083`](https://github.com/statelyai/xstate/commit/c7927083a651e3c51952ade2ffda793df0391bf6) [#1516](https://github.com/statelyai/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` function returned from the `useService()` now can take two arguments (an event type and payload), to match the behavior of `@xstate/react` version 0.x.
* [`db77623a`](https://github.com/davidkpiano/xstate/commit/db77623a48955d762cffa9b624f438220add5eed) [#1516](https://github.com/davidkpiano/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `send` value returned from the `useService()` hook will now accept a payload, which matches the signature of the `send` value returned from the `useMachine()` hook:
* [`db77623a`](https://github.com/statelyai/xstate/commit/db77623a48955d762cffa9b624f438220add5eed) [#1516](https://github.com/statelyai/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` value returned from the `useService()` hook will now accept a payload, which matches the signature of the `send` value returned from the `useMachine()` hook:

@@ -343,5 +363,5 @@ ```js

- [`93f6db02`](https://github.com/davidkpiano/xstate/commit/93f6db02a2d56ec997198ddef0af3d7730bb79bb) [#1594](https://github.com/davidkpiano/xstate/pull/1594) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with internal `setState` in `useService` being called with 2 arguments instead of 1.
- [`93f6db02`](https://github.com/statelyai/xstate/commit/93f6db02a2d56ec997198ddef0af3d7730bb79bb) [#1594](https://github.com/statelyai/xstate/pull/1594) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with internal `setState` in `useService` being called with 2 arguments instead of 1.
* [`72b0880e`](https://github.com/davidkpiano/xstate/commit/72b0880e6444ae009adca72088872bb5c0760ce3) [#1504](https://github.com/davidkpiano/xstate/pull/1504) Thanks [@Andarist](https://github.com/Andarist)! - Fixed issue with `useService` returning an initial state for services in their final states.
* [`72b0880e`](https://github.com/statelyai/xstate/commit/72b0880e6444ae009adca72088872bb5c0760ce3) [#1504](https://github.com/statelyai/xstate/pull/1504) Thanks [@Andarist](https://github.com/Andarist)! - Fixed issue with `useService` returning an initial state for services in their final states.

@@ -352,3 +372,3 @@ ## 1.0.1

- [`c0bd0407`](https://github.com/davidkpiano/xstate/commit/c0bd040767dcac20ed690e49a8725b4f1011dd5d) [#1493](https://github.com/davidkpiano/xstate/pull/1493) Thanks [@davidkpiano](https://github.com/davidkpiano)! - There will now be a descriptive error when trying to use an actor-like object in the `useService()` hook, where `useActor()` should be preferred:
- [`c0bd0407`](https://github.com/statelyai/xstate/commit/c0bd040767dcac20ed690e49a8725b4f1011dd5d) [#1493](https://github.com/statelyai/xstate/pull/1493) Thanks [@davidkpiano](https://github.com/statelyai)! - There will now be a descriptive error when trying to use an actor-like object in the `useService()` hook, where `useActor()` should be preferred:

@@ -355,0 +375,0 @@ > Attempted to use an actor-like object instead of a service in the useService() hook. Please use the useActor() hook instead.

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("xstate"),require("xstate/lib/behaviors")):"function"==typeof define&&define.amd?define(["exports","react","xstate","xstate/lib/behaviors"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateReact={},t.React,t.XState,t.behaviors)}(this,(function(t,e,n,r){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i,o=u(e),c=function(){return(c=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("xstate")):"function"==typeof define&&define.amd?define(["exports","react","xstate"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateReact={},t.React,t.XState)}(this,(function(t,e,n){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var u,o=r(e),c=function(){return(c=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};
/*! *****************************************************************************

@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,u,i=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)o.push(r.value)}catch(t){u={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(u)throw u.error}}return o}function f(t,e,n){if(n||2===arguments.length)for(var r,u=0,i=e.length;u<i;u++)!r&&u in e||(r||(r=Array.prototype.slice.call(e,0,u)),r[u]=e[u]);return t.concat(r||Array.prototype.slice.call(e))}!function(t){t[t.Effect=1]="Effect",t[t.LayoutEffect=2]="LayoutEffect"}(i||(i={}));var s=e.useLayoutEffect;function l(t){var n=e.useRef();return n.current||(n.current={v:t()}),n.current.v}function v(t,e){var n,r,u=a([[],[]],2),i=u[0],o=u[1];try{for(var c=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),f=c.next();!f.done;f=c.next()){var s=f.value;e(s)?i.push(s):o.push(s)}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}return[i,o]}function p(t,e){(0,t.exec)(e.context,e._event.data,{action:t,state:e,_event:e._event})()}function b(t,r,u){void 0===r&&(r={});var o=l((function(){return"function"==typeof t?t():t})),b=r.context,d=r.guards,y=r.actions,h=r.activities,g=r.services,O=r.delays,j=r.state,m=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(r=Object.getOwnPropertySymbols(t);u<r.length;u++)e.indexOf(r[u])<0&&Object.prototype.propertyIsEnumerable.call(t,r[u])&&(n[r[u]]=t[r[u]])}return n}(r,["context","guards","actions","activities","services","delays","state"]),x=l((function(){var t={context:b,guards:d,actions:y,activities:h,services:g,delays:O},e=o.withConfig(t,(function(){return c(c({},o.context),b)}));return n.interpret(e,c({deferEvents:!0},m))}));return s((function(){var t;return u&&(t=x.subscribe(function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(u))),function(){null==t||t.unsubscribe()}}),[u]),s((function(){return x.start(j?n.State.create(j):void 0),function(){x.stop()}}),[]),s((function(){Object.assign(x.machine.options.actions,y),Object.assign(x.machine.options.guards,d),Object.assign(x.machine.options.activities,h),Object.assign(x.machine.options.services,g),Object.assign(x.machine.options.delays,O)}),[y,d,h,g,O]),function(t){var n=e.useRef([]),r=e.useRef([]);s((function(){var e=t.subscribe((function(t){var e,u;if(t.actions.length){var o=a(v(t.actions.filter((function(t){return"function"==typeof t.exec&&"__effect"in t.exec})),(function(t){return t.exec.__effect===i.Effect})),2),c=o[0],s=o[1];(e=n.current).push.apply(e,f([],a(c.map((function(e){return[e,t]}))),!1)),(u=r.current).push.apply(u,f([],a(s.map((function(e){return[e,t]}))),!1))}}));return function(){e.unsubscribe()}}),[]),s((function(){for(;r.current.length;){var t=a(r.current.shift(),2);p(t[0],t[1])}})),e.useEffect((function(){for(;n.current.length;){var t=a(n.current.shift(),2);p(t[0],t[1])}}))}(x),x}function d(t,e){var n=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return function(){return t.apply(void 0,f([],a(e),!1))}};return Object.defineProperties(n,{name:{value:"effect:".concat(t.name)},__effect:{value:e}}),n}function y(t){return"state"in t}function h(t){return"deferred"in t}var g=function(){};function O(t){return"getSnapshot"in t?t.getSnapshot():y(t)?t.state:void 0}function j(t,n){void 0===n&&(n=O);var r=e.useRef(t),u=e.useRef([]),i=a(e.useState((function(){return n(t)})),2),o=i[0],c=i[1],f=l((function(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],i=r.current;h(i)&&i.deferred?u.current.push(n):i.send(n)}}));return s((function(){r.current=t,c(n(t));for(var e=t.subscribe({next:function(t){return c(t)},error:g,complete:g});u.current.length>0;){var i=u.current.shift();t.send(i)}return function(){e.unsubscribe()}}),[t]),[o,f]}function m(t){var e={exports:{}};return t(e,e.exports),e.exports
***************************************************************************** */function i(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(r=Object.getOwnPropertySymbols(t);u<r.length;u++)e.indexOf(r[u])<0&&Object.prototype.propertyIsEnumerable.call(t,r[u])&&(n[r[u]]=t[r[u]])}return n}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,u,o=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)c.push(r.value)}catch(t){u={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(u)throw u.error}}return c}function f(t,e,n){if(n||2===arguments.length)for(var r,u=0,o=e.length;u<o;u++)!r&&u in e||(r||(r=Array.prototype.slice.call(e,0,u)),r[u]=e[u]);return t.concat(r||Array.prototype.slice.call(e))}!function(t){t[t.Effect=1]="Effect",t[t.LayoutEffect=2]="LayoutEffect"}(u||(u={}));var s=e.useLayoutEffect;function l(t){var n=e.useRef();return n.current||(n.current={v:t()}),n.current.v}function v(t,e){var n,r,u=a([[],[]],2),o=u[0],c=u[1];try{for(var i=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),f=i.next();!f.done;f=i.next()){var s=f.value;e(s)?o.push(s):c.push(s)}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return[o,c]}function p(t,e){(0,t.exec)(e.context,e._event.data,{action:t,state:e,_event:e._event})()}function b(t){var n=e.useRef([]),r=e.useRef([]);s((function(){var e=t.subscribe((function(t){var e,o;if(t.actions.length){var c=a(v(t.actions.filter((function(t){return"function"==typeof t.exec&&"__effect"in t.exec})),(function(t){return t.exec.__effect===u.Effect})),2),i=c[0],s=c[1];(e=n.current).push.apply(e,f([],a(i.map((function(e){return[e,t]}))),!1)),(o=r.current).push.apply(o,f([],a(s.map((function(e){return[e,t]}))),!1))}}));return function(){e.unsubscribe()}}),[]),s((function(){for(;r.current.length;){var t=a(r.current.shift(),2);p(t[0],t[1])}})),e.useEffect((function(){for(;n.current.length;){var t=a(n.current.shift(),2);p(t[0],t[1])}}))}function y(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function d(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];var u=a(e,2),o=u[0],f=void 0===o?{}:o,v=u[1],p=l((function(){return"function"==typeof t?t():t})),d=f.context,h=f.guards,g=f.actions,O=f.services,j=f.delays,m=f.state,S=i(f,["context","guards","actions","services","delays","state"]),x=f.activities,w=l((function(){var t={context:d,guards:h,actions:g,activities:x,services:O,delays:j},e=p.withConfig(t,(function(){return c(c({},p.context),d)}));return n.interpret(e,c({deferEvents:!0},S))}));return s((function(){var t;return v&&(t=w.subscribe(y(v))),function(){null==t||t.unsubscribe()}}),[v]),s((function(){return w.start(m?n.State.create(m):void 0),function(){w.stop()}}),[]),s((function(){Object.assign(w.machine.options.actions,g),Object.assign(w.machine.options.guards,h),Object.assign(w.machine.options.activities,x),Object.assign(w.machine.options.services,O),Object.assign(w.machine.options.delays,j)}),[g,h,x,O,j]),b(w),w}function h(t,e){var n=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return function(){return t.apply(void 0,f([],a(e),!1))}};return Object.defineProperties(n,{name:{value:"effect:".concat(t.name)},__effect:{value:e}}),n}function g(t){return"state"in t}function O(t){return"deferred"in t}var j=function(){};function m(t){return"getSnapshot"in t?t.getSnapshot():g(t)?t.state:void 0}function S(t){var e={exports:{}};return t(e,e.exports),e.exports
/*

@@ -21,3 +21,3 @@ object-assign

@license MIT
*/}var x=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;function E(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var _=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(t){r[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,r,u=E(t),i=1;i<arguments.length;i++){for(var o in n=Object(arguments[i]))S.call(n,o)&&(u[o]=n[o]);if(x){r=x(n);for(var c=0;c<r.length;c++)w.call(n,r[c])&&(u[r[c]]=n[r[c]])}}return u},C={useSubscription:function(t){var e=t.getCurrentValue,n=t.subscribe,r=o.default.useState((function(){return{getCurrentValue:e,subscribe:n,value:e()}}));t=r[0];var u=r[1];return r=t.value,t.getCurrentValue===e&&t.subscribe===n||(r=e(),u({getCurrentValue:e,subscribe:n,value:r})),o.default.useDebugValue(r),o.default.useEffect((function(){function t(){if(!r){var t=e();u((function(r){return r.getCurrentValue!==e||r.subscribe!==n||r.value===t?r:_({},r,{value:t})}))}}var r=!1,i=n(t);return t(),function(){r=!0,i()}}),[e,n]),r}},P=(m((function(t,e){})),m((function(t){t.exports=C})));
*/}var x=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;function C(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var _=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(t){r[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,r,u=C(t),o=1;o<arguments.length;o++){for(var c in n=Object(arguments[o]))w.call(n,c)&&(u[c]=n[c]);if(x){r=x(n);for(var i=0;i<r.length;i++)E.call(n,r[i])&&(u[r[i]]=n[r[i]])}}return u},P={useSubscription:function(t){var e=t.getCurrentValue,n=t.subscribe,r=o.default.useState((function(){return{getCurrentValue:e,subscribe:n,value:e()}}));t=r[0];var u=r[1];return r=t.value,t.getCurrentValue===e&&t.subscribe===n||(r=e(),u({getCurrentValue:e,subscribe:n,value:r})),o.default.useDebugValue(r),o.default.useEffect((function(){function t(){if(!r){var t=e();u((function(r){return r.getCurrentValue!==e||r.subscribe!==n||r.value===t?r:_({},r,{value:t})}))}}var r=!1,o=n(t);return t(),function(){r=!0,o()}}),[e,n]),r}},V=(S((function(t,e){})),S((function(t){t.exports=P})));
/** @license React vundefined

@@ -30,2 +30,2 @@ * use-subscription.production.min.js

* LICENSE file in the root directory of this source tree.
*/var V=function(t,e){return t===e},R=function(t){return"state"in(n=t)&&"machine"in n?0!==("status"in(e=t)?e.status:e._status)?e.state:e.machine.initialState:y(t)?t.state:void 0;var e,n};t.asEffect=function(t){return d(t,i.Effect)},t.asLayoutEffect=function(t){return d(t,i.LayoutEffect)},t.useActor=j,t.useInterpret=b,t.useMachine=function(t,r){void 0===r&&(r={});var u=e.useCallback((function(t){var e=void 0===t.changed&&Object.keys(t.children).length;(t.changed||e)&&f(t)}),[]),i=b(t,r,u),o=a(e.useState((function(){var t=i.machine.initialState;return r.state?n.State.create(r.state):t})),2),c=o[0],f=o[1];return[c,i.send,i]},t.useSelector=function(t,n,r,u){void 0===r&&(r=V),void 0===u&&(u=R);var i=e.useRef(n),o=e.useMemo((function(){var e,o=u(t),c=n(o);return{getSnapshot:function(){return o},getCurrentValue:function(){return c},setCurrentValue:function(t){c=t,null==e||e()},subscribe:function(n){e=n;var u=t.subscribe((function(t){o=t;var e=i.current(t);r(c,e)||(c=e,n())}));return function(){u.unsubscribe()}}}}),[t]),c=P.useSubscription(o),a=!1;if(i.current!==n){var f=n(o.getSnapshot());r(c,f)||(a=!0,c=f)}return s((function(){i.current=n,a&&o.setCurrentValue(c)})),c},t.useService=function(t){return[a(j(t),1)[0],t.send]},t.useSpawn=function(t){return l((function(){return r.spawnBehavior(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
*/var R=function(t,e){return t===e},k=function(t){return"state"in(n=t)&&"machine"in n?0!==(e=t).status?e.state:e.machine.initialState:g(t)?t.state:void 0;var e,n};t.asEffect=function(t){return h(t,u.Effect)},t.asLayoutEffect=function(t){return h(t,u.LayoutEffect)},t.useActor=function(t,n){void 0===n&&(n=m);var r=e.useRef(t),u=e.useRef([]),o=a(e.useState((function(){return n(t)})),2),c=o[0],i=o[1],f=l((function(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=r.current;O(o)&&o.deferred?u.current.push(n):o.send(n)}}));return s((function(){r.current=t,i(n(t));for(var e=t.subscribe({next:function(t){return i(t)},error:j,complete:j});u.current.length>0;){var o=u.current.shift();t.send(o)}return function(){e.unsubscribe()}}),[t]),[c,f]},t.useInterpret=d,t.useMachine=function(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=a(r,1),c=o[0],i=void 0===c?{}:c,f=e.useCallback((function(t){var e=void 0===t.changed&&Object.keys(t.children).length;(t.changed||e)&&p(t)}),[]),s=d(t,i,f),l=a(e.useState((function(){var t=s.machine.initialState;return i.state?n.State.create(i.state):t})),2),v=l[0],p=l[1];return[v,s.send,s]},t.useSelector=function(t,n,r,u){void 0===r&&(r=R),void 0===u&&(u=k);var o=e.useRef(n),c=e.useMemo((function(){var e,c=u(t),i=n(c);return{getSnapshot:function(){return c},getCurrentValue:function(){return i},setCurrentValue:function(t){i=t,null==e||e()},subscribe:function(n){e=n;var u=t.subscribe((function(t){c=t;var e=o.current(t);r(i,e)||(i=e,n())}));return function(){u.unsubscribe()}}}}),[t]),i=V.useSubscription(c),a=!1;if(o.current!==n){var f=n(c.getSnapshot());r(i,f)||(a=!0,i=f)}return s((function(){o.current=n,a&&c.setCurrentValue(i)})),i},t.useSpawn=function(t){return l((function(){return n.spawnBehavior(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
export { useMachine, asEffect, asLayoutEffect } from './useMachine';
export { useService } from './useService';
export { useActor } from './useActor';

@@ -4,0 +3,0 @@ export { useInterpret } from './useInterpret';

export { useMachine, asEffect, asLayoutEffect } from './useMachine';
export { useService } from './useService';
export { useActor } from './useActor';

@@ -4,0 +3,0 @@ export { useInterpret } from './useInterpret';

import { ActionMeta, ActionObject, EventObject, State, StateConfig } from 'xstate';
export declare type Sender<TEvent extends EventObject> = (event: TEvent) => void;
export interface Subscription {
unsubscribe(): void;
}
export interface Observer<T> {
next?: (value: T) => void;
error?: (errorValue: any) => void;
complete: () => void;
}
export interface Subscribable<T> {
subscribe(observer: Observer<T>): Subscription;
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
}
export declare type MaybeLazy<T> = T | (() => T);
declare type ExcludeType<A> = {
[K in Exclude<keyof A, 'type'>]: A[K];
};
declare type ExtractExtraParameters<A, T> = A extends {
type: T;
} ? ExcludeType<A> : never;
declare type ExtractSimple<A> = A extends any ? {} extends ExcludeType<A> ? A : never : never;
declare type NeverIfEmpty<T> = {} extends T ? never : T;
export interface PayloadSender<TEvent extends EventObject> {
/**
* Send an event object or just the event type, if the event has no other payload
*/
(event: TEvent | ExtractSimple<TEvent>['type']): void;
/**
* Send an event type and its payload
*/
<K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
}
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
send: Sender<TEvent>;
}
export declare type NoInfer<T> = [T][T extends any ? 0 : any];
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
export declare enum ReactEffectType {

@@ -63,3 +31,2 @@ Effect = 1,

];
export {};
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,2 @@

import { Sender } from './types';
import { ActorRef, EventObject } from 'xstate';
import { ActorRef, EventObject, Sender } from 'xstate';
export declare function isActorWithState<T extends ActorRef<any>>(actorRef: T): actorRef is T & {

@@ -4,0 +3,0 @@ state: any;

@@ -1,8 +0,13 @@

import { EventObject, StateMachine, State, Interpreter, InterpreterOptions, MachineOptions, Typestate, Observer } from 'xstate';
import { AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, Observer, StateFrom } from 'xstate';
import { MaybeLazy } from './types';
import { UseMachineOptions } from './useMachine';
export declare function useInterpret<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(getMachine: MaybeLazy<StateMachine<TContext, any, TEvent, TTypestate>>, options?: Partial<InterpreterOptions> & Partial<UseMachineOptions<TContext, TEvent>> & Partial<MachineOptions<TContext, TEvent>>, observerOrListener?: Observer<State<TContext, TEvent, any, TTypestate>> | ((value: State<TContext, TEvent, any, TTypestate>) => void)): Interpreter<TContext, any, TEvent, TTypestate>;
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>,
observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
] : [
options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>,
observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
];
export declare function useInterpret<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options, observerOrListener]: RestParams<TMachine>): InterpreterFrom<TMachine>;
export {};
//# sourceMappingURL=useInterpret.d.ts.map

@@ -57,4 +57,8 @@ var __assign = (this && this.__assign) || function () {

}
export function useInterpret(getMachine, options, observerOrListener) {
if (options === void 0) { options = {}; }
export function useInterpret(getMachine) {
var _a = [];
for (var _i = 1; _i < arguments.length; _i++) {
_a[_i - 1] = arguments[_i];
}
var _b = __read(_a, 2), _c = _b[0], options = _c === void 0 ? {} : _c, observerOrListener = _b[1];
var machine = useConstant(function () {

@@ -65,3 +69,3 @@ return typeof getMachine === 'function' ? getMachine() : getMachine;

typeof getMachine !== 'function') {
var _a = __read(useState(machine), 1), initialMachine = _a[0];
var _d = __read(useState(machine), 1), initialMachine = _d[0];
if (getMachine !== initialMachine) {

@@ -72,3 +76,5 @@ console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\n' +

}
var context = options.context, guards = options.guards, actions = options.actions, activities = options.activities, services = options.services, delays = options.delays, rehydratedState = options.state, interpreterOptions = __rest(options, ["context", "guards", "actions", "activities", "services", "delays", "state"]);
var context = options.context, guards = options.guards, actions = options.actions, services = options.services, delays = options.delays, rehydratedState = options.state, interpreterOptions = __rest(options, ["context", "guards", "actions", "services", "delays", "state"]);
// it's not defined in `TypegenMachineOptions` so we can't just unpack this property here freely
var activities = options.activities;
var service = useConstant(function () {

@@ -75,0 +81,0 @@ var machineConfig = {

@@ -1,3 +0,3 @@

import { EventObject, StateMachine, State, Interpreter, InterpreterOptions, MachineOptions, StateConfig, Typestate, ActionFunction } from 'xstate';
import { MaybeLazy, ReactActionFunction } from './types';
import { ActionFunction, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, EventObject, InternalMachineOptions, InterpreterFrom, InterpreterOptions, StateConfig, StateFrom } from 'xstate';
import { MaybeLazy, Prop, ReactActionFunction } from './types';
export declare function asEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;

@@ -16,10 +16,10 @@ export declare function asLayoutEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;

}
export declare function useMachine<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(getMachine: MaybeLazy<StateMachine<TContext, any, TEvent, TTypestate>>, options?: Partial<InterpreterOptions> & Partial<UseMachineOptions<TContext, TEvent>> & Partial<MachineOptions<TContext, TEvent>>): [
State<TContext, TEvent, any, TTypestate>,
Interpreter<TContext, any, TEvent, TTypestate>['send'],
Interpreter<TContext, any, TEvent, TTypestate>
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>
] : [
options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>
];
declare type UseMachineReturn<TMachine extends AnyStateMachine, TInterpreter = InterpreterFrom<TMachine>> = [StateFrom<TMachine>, Prop<TInterpreter, 'send'>, TInterpreter];
export declare function useMachine<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options]: RestParams<TMachine>): UseMachineReturn<TMachine>;
export {};
//# sourceMappingURL=useMachine.d.ts.map

@@ -53,4 +53,8 @@ var __read = (this && this.__read) || function (o, n) {

}
export function useMachine(getMachine, options) {
if (options === void 0) { options = {}; }
export function useMachine(getMachine) {
var _a = [];
for (var _i = 1; _i < arguments.length; _i++) {
_a[_i - 1] = arguments[_i];
}
var _b = __read(_a, 1), _c = _b[0], options = _c === void 0 ? {} : _c;
var listener = useCallback(function (nextState) {

@@ -62,4 +66,3 @@ // Only change the current state if:

// The "live" initial state will have .changed === undefined.
var initialStateChanged = nextState.changed === undefined &&
Object.keys(nextState.children).length;
var initialStateChanged = nextState.changed === undefined && Object.keys(nextState.children).length;
if (nextState.changed || initialStateChanged) {

@@ -70,3 +73,3 @@ setState(nextState);

var service = useInterpret(getMachine, options, listener);
var _a = __read(useState(function () {
var _d = __read(useState(function () {
var initialState = service.machine.initialState;

@@ -76,4 +79,4 @@ return (options.state

: initialState);
}), 2), state = _a[0], setState = _a[1];
}), 2), state = _d[0], setState = _d[1];
return [state, service.send, service];
}

@@ -69,3 +69,3 @@ var __read = (this && this.__read) || function (o, n) {

}
}); // https://github.com/davidkpiano/xstate/pull/1202#discussion_r429677773
}); // https://github.com/statelyai/xstate/pull/1202#discussion_r429677773
useEffect(function () {

@@ -72,0 +72,0 @@ while (effectActionsRef.current.length) {

@@ -5,3 +5,3 @@ import { useMemo, useRef } from 'react';

import { isActorWithState } from './useActor';
import { getServiceSnapshot } from './useService';
import { getServiceSnapshot } from './utils';
function isService(actor) {

@@ -8,0 +8,0 @@ return 'state' in actor && 'machine' in actor;

@@ -1,2 +0,2 @@

import { spawnBehavior } from 'xstate/lib/behaviors';
import { spawnBehavior } from 'xstate';
import useConstant from './useConstant';

@@ -3,0 +3,0 @@ /**

@@ -0,2 +1,4 @@

import { Interpreter } from 'xstate';
export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
export declare function getServiceSnapshot<TService extends Interpreter<any, any, any, any>>(service: TService): TService['state'];
//# sourceMappingURL=utils.d.ts.map

@@ -51,1 +51,4 @@ var __read = (this && this.__read) || function (o, n) {

}
export function getServiceSnapshot(service) {
return service.status !== 0 ? service.state : service.machine.initialState;
}
export { useMachine, asEffect, asLayoutEffect } from './useMachine';
export { useService } from './useService';
export { useActor } from './useActor';

@@ -4,0 +3,0 @@ export { useInterpret } from './useInterpret';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSpawn = exports.useSelector = exports.useInterpret = exports.useActor = exports.useService = exports.asLayoutEffect = exports.asEffect = exports.useMachine = void 0;
exports.useSpawn = exports.useSelector = exports.useInterpret = exports.useActor = exports.asLayoutEffect = exports.asEffect = exports.useMachine = void 0;
var useMachine_1 = require("./useMachine");

@@ -8,4 +8,2 @@ Object.defineProperty(exports, "useMachine", { enumerable: true, get: function () { return useMachine_1.useMachine; } });

Object.defineProperty(exports, "asLayoutEffect", { enumerable: true, get: function () { return useMachine_1.asLayoutEffect; } });
var useService_1 = require("./useService");
Object.defineProperty(exports, "useService", { enumerable: true, get: function () { return useService_1.useService; } });
var useActor_1 = require("./useActor");

@@ -12,0 +10,0 @@ Object.defineProperty(exports, "useActor", { enumerable: true, get: function () { return useActor_1.useActor; } });

import { ActionMeta, ActionObject, EventObject, State, StateConfig } from 'xstate';
export declare type Sender<TEvent extends EventObject> = (event: TEvent) => void;
export interface Subscription {
unsubscribe(): void;
}
export interface Observer<T> {
next?: (value: T) => void;
error?: (errorValue: any) => void;
complete: () => void;
}
export interface Subscribable<T> {
subscribe(observer: Observer<T>): Subscription;
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
}
export declare type MaybeLazy<T> = T | (() => T);
declare type ExcludeType<A> = {
[K in Exclude<keyof A, 'type'>]: A[K];
};
declare type ExtractExtraParameters<A, T> = A extends {
type: T;
} ? ExcludeType<A> : never;
declare type ExtractSimple<A> = A extends any ? {} extends ExcludeType<A> ? A : never : never;
declare type NeverIfEmpty<T> = {} extends T ? never : T;
export interface PayloadSender<TEvent extends EventObject> {
/**
* Send an event object or just the event type, if the event has no other payload
*/
(event: TEvent | ExtractSimple<TEvent>['type']): void;
/**
* Send an event type and its payload
*/
<K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
}
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
send: Sender<TEvent>;
}
export declare type NoInfer<T> = [T][T extends any ? 0 : any];
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
export declare enum ReactEffectType {

@@ -63,3 +31,2 @@ Effect = 1,

];
export {};
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,2 @@

import { Sender } from './types';
import { ActorRef, EventObject } from 'xstate';
import { ActorRef, EventObject, Sender } from 'xstate';
export declare function isActorWithState<T extends ActorRef<any>>(actorRef: T): actorRef is T & {

@@ -4,0 +3,0 @@ state: any;

@@ -1,8 +0,13 @@

import { EventObject, StateMachine, State, Interpreter, InterpreterOptions, MachineOptions, Typestate, Observer } from 'xstate';
import { AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, Observer, StateFrom } from 'xstate';
import { MaybeLazy } from './types';
import { UseMachineOptions } from './useMachine';
export declare function useInterpret<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(getMachine: MaybeLazy<StateMachine<TContext, any, TEvent, TTypestate>>, options?: Partial<InterpreterOptions> & Partial<UseMachineOptions<TContext, TEvent>> & Partial<MachineOptions<TContext, TEvent>>, observerOrListener?: Observer<State<TContext, TEvent, any, TTypestate>> | ((value: State<TContext, TEvent, any, TTypestate>) => void)): Interpreter<TContext, any, TEvent, TTypestate>;
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>,
observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
] : [
options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>,
observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
];
export declare function useInterpret<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options, observerOrListener]: RestParams<TMachine>): InterpreterFrom<TMachine>;
export {};
//# sourceMappingURL=useInterpret.d.ts.map

@@ -60,4 +60,8 @@ "use strict";

}
function useInterpret(getMachine, options, observerOrListener) {
if (options === void 0) { options = {}; }
function useInterpret(getMachine) {
var _a = [];
for (var _i = 1; _i < arguments.length; _i++) {
_a[_i - 1] = arguments[_i];
}
var _b = __read(_a, 2), _c = _b[0], options = _c === void 0 ? {} : _c, observerOrListener = _b[1];
var machine = (0, useConstant_1.default)(function () {

@@ -68,3 +72,3 @@ return typeof getMachine === 'function' ? getMachine() : getMachine;

typeof getMachine !== 'function') {
var _a = __read((0, react_1.useState)(machine), 1), initialMachine = _a[0];
var _d = __read((0, react_1.useState)(machine), 1), initialMachine = _d[0];
if (getMachine !== initialMachine) {

@@ -75,3 +79,5 @@ console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\n' +

}
var context = options.context, guards = options.guards, actions = options.actions, activities = options.activities, services = options.services, delays = options.delays, rehydratedState = options.state, interpreterOptions = __rest(options, ["context", "guards", "actions", "activities", "services", "delays", "state"]);
var context = options.context, guards = options.guards, actions = options.actions, services = options.services, delays = options.delays, rehydratedState = options.state, interpreterOptions = __rest(options, ["context", "guards", "actions", "services", "delays", "state"]);
// it's not defined in `TypegenMachineOptions` so we can't just unpack this property here freely
var activities = options.activities;
var service = (0, useConstant_1.default)(function () {

@@ -78,0 +84,0 @@ var machineConfig = {

@@ -1,3 +0,3 @@

import { EventObject, StateMachine, State, Interpreter, InterpreterOptions, MachineOptions, StateConfig, Typestate, ActionFunction } from 'xstate';
import { MaybeLazy, ReactActionFunction } from './types';
import { ActionFunction, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, EventObject, InternalMachineOptions, InterpreterFrom, InterpreterOptions, StateConfig, StateFrom } from 'xstate';
import { MaybeLazy, Prop, ReactActionFunction } from './types';
export declare function asEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;

@@ -16,10 +16,10 @@ export declare function asLayoutEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;

}
export declare function useMachine<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(getMachine: MaybeLazy<StateMachine<TContext, any, TEvent, TTypestate>>, options?: Partial<InterpreterOptions> & Partial<UseMachineOptions<TContext, TEvent>> & Partial<MachineOptions<TContext, TEvent>>): [
State<TContext, TEvent, any, TTypestate>,
Interpreter<TContext, any, TEvent, TTypestate>['send'],
Interpreter<TContext, any, TEvent, TTypestate>
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>
] : [
options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>
];
declare type UseMachineReturn<TMachine extends AnyStateMachine, TInterpreter = InterpreterFrom<TMachine>> = [StateFrom<TMachine>, Prop<TInterpreter, 'send'>, TInterpreter];
export declare function useMachine<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options]: RestParams<TMachine>): UseMachineReturn<TMachine>;
export {};
//# sourceMappingURL=useMachine.d.ts.map

@@ -58,4 +58,8 @@ "use strict";

exports.asLayoutEffect = asLayoutEffect;
function useMachine(getMachine, options) {
if (options === void 0) { options = {}; }
function useMachine(getMachine) {
var _a = [];
for (var _i = 1; _i < arguments.length; _i++) {
_a[_i - 1] = arguments[_i];
}
var _b = __read(_a, 1), _c = _b[0], options = _c === void 0 ? {} : _c;
var listener = (0, react_1.useCallback)(function (nextState) {

@@ -67,4 +71,3 @@ // Only change the current state if:

// The "live" initial state will have .changed === undefined.
var initialStateChanged = nextState.changed === undefined &&
Object.keys(nextState.children).length;
var initialStateChanged = nextState.changed === undefined && Object.keys(nextState.children).length;
if (nextState.changed || initialStateChanged) {

@@ -75,3 +78,3 @@ setState(nextState);

var service = (0, useInterpret_1.useInterpret)(getMachine, options, listener);
var _a = __read((0, react_1.useState)(function () {
var _d = __read((0, react_1.useState)(function () {
var initialState = service.machine.initialState;

@@ -81,5 +84,5 @@ return (options.state

: initialState);
}), 2), state = _a[0], setState = _a[1];
}), 2), state = _d[0], setState = _d[1];
return [state, service.send, service];
}
exports.useMachine = useMachine;

@@ -72,3 +72,3 @@ "use strict";

}
}); // https://github.com/davidkpiano/xstate/pull/1202#discussion_r429677773
}); // https://github.com/statelyai/xstate/pull/1202#discussion_r429677773
(0, react_1.useEffect)(function () {

@@ -75,0 +75,0 @@ while (effectActionsRef.current.length) {

@@ -8,3 +8,3 @@ "use strict";

var useActor_1 = require("./useActor");
var useService_1 = require("./useService");
var utils_1 = require("./utils");
function isService(actor) {

@@ -16,3 +16,3 @@ return 'state' in actor && 'machine' in actor;

return isService(a)
? (0, useService_1.getServiceSnapshot)(a)
? (0, utils_1.getServiceSnapshot)(a)
: (0, useActor_1.isActorWithState)(a)

@@ -19,0 +19,0 @@ ? a.state

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSpawn = void 0;
var behaviors_1 = require("xstate/lib/behaviors");
var xstate_1 = require("xstate");
var useConstant_1 = require("./useConstant");

@@ -15,3 +15,3 @@ /**

var actorRef = (0, useConstant_1.default)(function () {
return (0, behaviors_1.spawnBehavior)(behavior);
return (0, xstate_1.spawnBehavior)(behavior);
});

@@ -18,0 +18,0 @@ return actorRef;

@@ -0,2 +1,4 @@

import { Interpreter } from 'xstate';
export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
export declare function getServiceSnapshot<TService extends Interpreter<any, any, any, any>>(service: TService): TService['state'];
//# sourceMappingURL=utils.d.ts.map

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.partition = void 0;
exports.getServiceSnapshot = exports.partition = void 0;
function partition(items, predicate) {

@@ -56,1 +56,5 @@ var e_1, _a;

exports.partition = partition;
function getServiceSnapshot(service) {
return service.status !== 0 ? service.state : service.machine.initialState;
}
exports.getServiceSnapshot = getServiceSnapshot;
{
"name": "@xstate/react",
"version": "1.6.3",
"version": "2.0.1",
"description": "XState tools for React",

@@ -16,3 +16,3 @@ "keywords": [

"author": "David Khourshid <davidkpiano@gmail.com>",
"homepage": "https://github.com/davidkpiano/xstate/tree/main/packages/xstate-react#readme",
"homepage": "https://github.com/statelyai/xstate/tree/main/packages/xstate-react#readme",
"license": "MIT",

@@ -22,2 +22,9 @@ "main": "lib/index.js",

"types": "lib/index.d.ts",
"typesVersions": {
"<4.0": {
"lib/index.d.ts": [
"index.v3.d.ts"
]
}
},
"sideEffects": false,

@@ -38,3 +45,3 @@ "directories": {

"type": "git",
"url": "git+ssh://git@github.com/davidkpiano/xstate.git"
"url": "git+ssh://git@github.com/statelyai/xstate.git"
},

@@ -45,11 +52,11 @@ "scripts": {

"test": "jest",
"prepublish": "npm run build"
"prepare": "npm run build"
},
"bugs": {
"url": "https://github.com/davidkpiano/xstate/issues"
"url": "https://github.com/statelyai/xstate/issues"
},
"peerDependencies": {
"@xstate/fsm": "^1.0.0",
"@xstate/fsm": "^1.6.5",
"react": "^16.8.0 || ^17.0.0",
"xstate": "^4.11.0"
"xstate": "^4.30.3"
},

@@ -56,0 +63,0 @@ "peerDependenciesMeta": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc