@xstate/react 2.0.0 → 3.0.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.
@@ -1,4 +1,42 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@xstate/fsm")):"function"==typeof define&&define.amd?define(["exports","react","@xstate/fsm"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateReactFSM={},e.React,e.XStateFSM)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=n(t);
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xstate/fsm"),require("react")):"function"==typeof define&&define.amd?define(["exports","@xstate/fsm","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateReactFSM={},e.XStateFSM,e.React)}(this,(function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o=r(n),c=u(n);var a=n.useLayoutEffect;function f(e){var t={exports:{}};return e(t,t.exports),t.exports
2
+ /**
3
+ * @license React
4
+ * use-sync-external-store-shim.production.min.js
5
+ *
6
+ * Copyright (c) Facebook, Inc. and its affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */}var i="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},s=o.default.useState,l=o.default.useEffect,d=o.default.useLayoutEffect,v=o.default.useDebugValue;function p(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch(e){return!0}}var b="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),r=s({inst:{value:n,getSnapshot:t}}),u=r[0].inst,o=r[1];return d((function(){u.value=n,u.getSnapshot=t,p(u)&&o({inst:u})}),[e,n,t]),l((function(){return p(u)&&o({inst:u}),e((function(){p(u)&&o({inst:u})}))}),[e]),v(n),n},y={useSyncExternalStore:void 0!==o.default.useSyncExternalStore?o.default.useSyncExternalStore:b};
11
+ /**
12
+ * @license React
13
+ * use-sync-external-store-shim.development.js
14
+ *
15
+ * Copyright (c) Facebook, Inc. and its affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ */
20
+ f((function(e,t){}));var S=f((function(e){e.exports=y}));
21
+ /**
22
+ * @license React
23
+ * use-sync-external-store-shim/with-selector.production.min.js
24
+ *
25
+ * Copyright (c) Facebook, Inc. and its affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */var h="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},x=S.useSyncExternalStore,E=o.default.useRef,g=o.default.useEffect,j=o.default.useMemo,m=o.default.useDebugValue,O={useSyncExternalStoreWithSelector:function(e,t,n,r,u){var o=E(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=j((function(){function e(e){if(!f){if(f=!0,o=e,e=r(e),void 0!==u&&c.hasValue){var t=c.value;if(u(t,e))return a=t}return a=e}if(t=a,h(o,e))return t;var n=r(e);return void 0!==u&&u(t,n)?t:(o=e,a=n)}var o,a,f=!1,i=void 0===n?null:n;return[function(){return e(t())},null===i?void 0:function(){return e(i())}]}),[t,n,r,u]);var a=x(e,o[0],o[1]);return g((function(){c.hasValue=!0,c.value=a}),[a]),m(a),a}};
30
+ /**
31
+ * @license React
32
+ * use-sync-external-store-shim/with-selector.development.js
33
+ *
34
+ * Copyright (c) Facebook, Inc. and its affiliates.
35
+ *
36
+ * This source code is licensed under the MIT license found in the
37
+ * LICENSE file in the root directory of this source tree.
38
+ */
39
+ f((function(e,t){}));var w=f((function(e){e.exports=O}));function M(e){return e}var _=function(e,t){return!1===t.changed};function R(e){var t=n.useCallback((function(){return function(e){var t;return e.subscribe((function(e){t=e})).unsubscribe(),t}(e)}),[e]),r=n.useCallback((function(t){return e.subscribe(t).unsubscribe}),[e]);return[w.useSyncExternalStoreWithSelector(r,t,t,M,_),e.send,e]}e.useMachine=function(e,r){var u,o,f=n.useRef(),i=
2
40
  /*! *****************************************************************************
3
41
  Copyright (c) Microsoft Corporation.
4
42
 
@@ -12,17 +50,5 @@
12
50
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
51
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
52
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function o(e){var t={exports:{}};return e(t,t.exports),t.exports
16
- /*
17
- object-assign
18
- (c) Sindre Sorhus
19
- @license MIT
20
- */}var i=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function f(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}var s=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(e){n[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var r,n,u=f(e),o=1;o<arguments.length;o++){for(var s in r=Object(arguments[o]))c.call(r,s)&&(u[s]=r[s]);if(i){n=i(r);for(var l=0;l<n.length;l++)a.call(r,n[l])&&(u[n[l]]=r[n[l]])}}return u},l={useSubscription:function(e){var t=e.getCurrentValue,r=e.subscribe,n=u.default.useState((function(){return{getCurrentValue:t,subscribe:r,value:t()}}));e=n[0];var o=n[1];return n=e.value,e.getCurrentValue===t&&e.subscribe===r||(n=t(),o({getCurrentValue:t,subscribe:r,value:n})),u.default.useDebugValue(n),u.default.useEffect((function(){function e(){if(!n){var e=t();o((function(n){return n.getCurrentValue!==t||n.subscribe!==r||n.value===e?n:s({},n,{value:e})}))}}var n=!1,u=r(e);return e(),function(){n=!0,u()}}),[t,r]),n}},b=(o((function(e,t){})),o((function(e){e.exports=l})));
21
- /** @license React vundefined
22
- * use-subscription.production.min.js
23
- *
24
- * Copyright (c) Facebook, Inc. and its affiliates.
25
- *
26
- * This source code is licensed under the MIT license found in the
27
- * LICENSE file in the root directory of this source tree.
28
- */var p=function(e){var t;return e.subscribe((function(e){t=e})).unsubscribe(),t};e.useMachine=function(e,n){var u,o,i=(u=function(){return r.interpret(r.createMachine(e.config,n||e._options)).start()},(o=t.useRef()).current||(o.current={v:u()}),o.current.v),c=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,u,o=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(e){u={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(u)throw u.error}}return i}(t.useState((function(){return p(i)})),2),a=c[0],f=c[1];return t.useEffect((function(){n&&(i._machine._options=n)})),t.useEffect((function(){return i.subscribe(f),function(){i.stop()}}),[]),[a,i.send,i]},e.useService=function(e){var r=t.useMemo((function(){var t=p(e);return{getCurrentValue:function(){return t},subscribe:function(r){return e.subscribe((function(e){!1!==e.changed&&(t=e,r())})).unsubscribe}}}),[e]);return[b.useSubscription(r),e.send,e]},Object.defineProperty(e,"__esModule",{value:!0})}));
53
+ ***************************************************************************** */
54
+ function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,u,o=n.call(e),c=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)c.push(r.value)}catch(e){u={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(u)throw u.error}}return c}((u=function(){var n=[],u=t.interpret(t.createMachine(e.config,r||e._options)),o=u.send;return u.send=function(e){u.status!==t.InterpreterStatus.NotStarted?(o(e),f.current=u.state):n.push(e)},[u,n]},(o=c.useRef()).current||(o.current={v:u()}),o.current.v),2),s=i[0],l=i[1];a((function(){r&&(s._machine._options=r)}));var d=R(s);return n.useEffect((function(){return s.start(f.current),l.forEach(s.send),f.current=s.state,function(){s.stop()}}),[]),d},e.useService=R,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,28 +1,39 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("xstate"),require("xstate/lib/behaviors")):"function"==typeof define&&define.amd?define(["exports","react","xstate","xstate/lib/behaviors"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateReact={},e.React,e.XState,e.behaviors)}(this,(function(e,t,n,r){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o,i=u(t),c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var u in t=arguments[n])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e}).apply(this,arguments)};
2
- /*! *****************************************************************************
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
- PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(r=Object.getOwnPropertySymbols(e);u<r.length;u++)t.indexOf(r[u])<0&&Object.prototype.propertyIsEnumerable.call(e,r[u])&&(n[r[u]]=e[r[u]])}return n}function f(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,u,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){u={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(u)throw u.error}}return i}function s(e,t,n){if(n||2===arguments.length)for(var r,u=0,o=t.length;u<o;u++)!r&&u in t||(r||(r=Array.prototype.slice.call(t,0,u)),r[u]=t[u]);return e.concat(r||Array.prototype.slice.call(t))}!function(e){e[e.Effect=1]="Effect",e[e.LayoutEffect=2]="LayoutEffect"}(o||(o={}));var l=t.useLayoutEffect;function v(e){var n=t.useRef();return n.current||(n.current={v:e()}),n.current.v}function p(e,t){var n,r,u=f([[],[]],2),o=u[0],i=u[1];try{for(var c=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(e),a=c.next();!a.done;a=c.next()){var s=a.value;t(s)?o.push(s):i.push(s)}}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}return[o,i]}function b(e,t){(0,e.exec)(t.context,t._event.data,{action:e,state:t,_event:t._event})()}function h(e){var n=t.useRef([]),r=t.useRef([]);l((function(){var t=e.subscribe((function(e){var t,u;if(e.actions.length){var i=f(p(e.actions.filter((function(e){return"function"==typeof e.exec&&"__effect"in e.exec})),(function(e){return e.exec.__effect===o.Effect})),2),c=i[0],a=i[1];(t=n.current).push.apply(t,s([],f(c.map((function(t){return[t,e]}))),!1)),(u=r.current).push.apply(u,s([],f(a.map((function(t){return[t,e]}))),!1))}}));return function(){t.unsubscribe()}}),[]),l((function(){for(;r.current.length;){var e=f(r.current.shift(),2);b(e[0],e[1])}})),t.useEffect((function(){for(;n.current.length;){var e=f(n.current.shift(),2);b(e[0],e[1])}}))}function y(e,t,n){if("object"==typeof e)return e;var r=function(){};return{next:e,error:t||r,complete:n||r}}function d(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var u=f(t,2),o=u[0],i=void 0===o?{}:o,s=u[1],p=v((function(){return"function"==typeof e?e():e})),b=i.context,d=i.guards,g=i.actions,O=i.services,j=i.delays,m=i.state,x=a(i,["context","guards","actions","services","delays","state"]),S=i.activities,w=v((function(){var e={context:b,guards:d,actions:g,activities:S,services:O,delays:j},t=p.withConfig(e,(function(){return c(c({},p.context),b)}));return n.interpret(t,c({deferEvents:!0},x))}));return l((function(){var e;return s&&(e=w.subscribe(y(s))),function(){null==e||e.unsubscribe()}}),[s]),l((function(){return w.start(m?n.State.create(m):void 0),function(){w.stop()}}),[]),l((function(){Object.assign(w.machine.options.actions,g),Object.assign(w.machine.options.guards,d),Object.assign(w.machine.options.activities,S),Object.assign(w.machine.options.services,O),Object.assign(w.machine.options.delays,j)}),[g,d,S,O,j]),h(w),w}function g(e,t){var n=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return function(){return e.apply(void 0,s([],f(t),!1))}};return Object.defineProperties(n,{name:{value:"effect:".concat(e.name)},__effect:{value:t}}),n}function O(e){return"state"in e}function j(e){return"deferred"in e}var m=function(){};function x(e){return"getSnapshot"in e?e.getSnapshot():O(e)?e.state:void 0}function S(e){var t={exports:{}};return e(t,t.exports),t.exports
16
- /*
17
- object-assign
18
- (c) Sindre Sorhus
19
- @license MIT
20
- */}var w=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;function _(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}var P=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,r,u=_(e),o=1;o<arguments.length;o++){for(var i in n=Object(arguments[o]))E.call(n,i)&&(u[i]=n[i]);if(w){r=w(n);for(var c=0;c<r.length;c++)C.call(n,r[c])&&(u[r[c]]=n[r[c]])}}return u},V={useSubscription:function(e){var t=e.getCurrentValue,n=e.subscribe,r=i.default.useState((function(){return{getCurrentValue:t,subscribe:n,value:t()}}));e=r[0];var u=r[1];return r=e.value,e.getCurrentValue===t&&e.subscribe===n||(r=t(),u({getCurrentValue:t,subscribe:n,value:r})),i.default.useDebugValue(r),i.default.useEffect((function(){function e(){if(!r){var e=t();u((function(r){return r.getCurrentValue!==t||r.subscribe!==n||r.value===e?r:P({},r,{value:e})}))}}var r=!1,o=n(e);return e(),function(){r=!0,o()}}),[t,n]),r}},R=(S((function(e,t){})),S((function(e){e.exports=V})));
21
- /** @license React vundefined
22
- * use-subscription.production.min.js
1
+ !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}}function u(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var a=r(e),o=u(e),i=function(){return(i=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 c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,u,a=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=a.next()).done;)o.push(r.value)}catch(t){u={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(u)throw u.error}}return o}function s(t){var e={exports:{}};return t(e,e.exports),e.exports
2
+ /**
3
+ * @license React
4
+ * use-sync-external-store-shim.production.min.js
23
5
  *
24
6
  * Copyright (c) Facebook, Inc. and its affiliates.
25
7
  *
26
8
  * This source code is licensed under the MIT license found in the
27
9
  * LICENSE file in the root directory of this source tree.
28
- */var k=function(e,t){return e===t},q=function(e){return"state"in(n=e)&&"machine"in n?0!==(t=e).status?t.state:t.machine.initialState:O(e)?e.state:void 0;var t,n};e.asEffect=function(e){return g(e,o.Effect)},e.asLayoutEffect=function(e){return g(e,o.LayoutEffect)},e.useActor=function(e,n){void 0===n&&(n=x);var r=t.useRef(e),u=t.useRef([]),o=f(t.useState((function(){return n(e)})),2),i=o[0],c=o[1],a=v((function(){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],o=r.current;j(o)&&o.deferred?u.current.push(n):o.send(n)}}));return l((function(){r.current=e,c(n(e));for(var t=e.subscribe({next:function(e){return c(e)},error:m,complete:m});u.current.length>0;){var o=u.current.shift();e.send(o)}return function(){t.unsubscribe()}}),[e]),[i,a]},e.useInterpret=d,e.useMachine=function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=f(r,1),i=o[0],c=void 0===i?{}:i,a=t.useCallback((function(e){var t=void 0===e.changed&&Object.keys(e.children).length;(e.changed||t)&&p(e)}),[]),s=d(e,c,a),l=f(t.useState((function(){var e=s.machine.initialState;return c.state?n.State.create(c.state):e})),2),v=l[0],p=l[1];return[v,s.send,s]},e.useSelector=function(e,n,r,u){void 0===r&&(r=k),void 0===u&&(u=q);var o=t.useRef(n),i=t.useMemo((function(){var t,i=u(e),c=n(i);return{getSnapshot:function(){return i},getCurrentValue:function(){return c},setCurrentValue:function(e){c=e,null==t||t()},subscribe:function(n){t=n;var u=e.subscribe((function(e){i=e;var t=o.current(e);r(c,t)||(c=t,n())}));return function(){u.unsubscribe()}}}}),[e]),c=R.useSubscription(i),a=!1;if(o.current!==n){var f=n(i.getSnapshot());r(c,f)||(a=!0,c=f)}return l((function(){o.current=n,a&&i.setCurrentValue(c)})),c},e.useSpawn=function(e){return v((function(){return r.spawnBehavior(e)}))},Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ */}var f="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},l=a.default.useState,v=a.default.useEffect,d=a.default.useLayoutEffect,p=a.default.useDebugValue;function b(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!f(t,n)}catch(t){return!0}}var y="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=l({inst:{value:n,getSnapshot:e}}),u=r[0].inst,a=r[1];return d((function(){u.value=n,u.getSnapshot=e,b(u)&&a({inst:u})}),[t,n,e]),v((function(){return b(u)&&a({inst:u}),t((function(){b(u)&&a({inst:u})}))}),[t]),p(n),n},h={useSyncExternalStore:void 0!==a.default.useSyncExternalStore?a.default.useSyncExternalStore:y};
11
+ /**
12
+ * @license React
13
+ * use-sync-external-store-shim.development.js
14
+ *
15
+ * Copyright (c) Facebook, Inc. and its affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ */
20
+ s((function(t,e){}));var S=s((function(t){t.exports=h}));
21
+ /**
22
+ * @license React
23
+ * use-sync-external-store-shim/with-selector.production.min.js
24
+ *
25
+ * Copyright (c) Facebook, Inc. and its affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */var g="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},O=S.useSyncExternalStore,j=a.default.useRef,x=a.default.useEffect,m=a.default.useMemo,E=a.default.useDebugValue,w={useSyncExternalStoreWithSelector:function(t,e,n,r,u){var a=j(null);if(null===a.current){var o={hasValue:!1,value:null};a.current=o}else o=a.current;a=m((function(){function t(t){if(!c){if(c=!0,a=t,t=r(t),void 0!==u&&o.hasValue){var e=o.value;if(u(e,t))return i=e}return i=t}if(e=i,g(a,t))return e;var n=r(t);return void 0!==u&&u(e,n)?e:(a=t,i=n)}var a,i,c=!1,s=void 0===n?null:n;return[function(){return t(e())},null===s?void 0:function(){return t(s())}]}),[e,n,r,u]);var i=O(t,a[0],a[1]);return x((function(){o.hasValue=!0,o.value=i}),[i]),E(i),i}};
30
+ /**
31
+ * @license React
32
+ * use-sync-external-store-shim/with-selector.development.js
33
+ *
34
+ * Copyright (c) Facebook, Inc. and its affiliates.
35
+ *
36
+ * This source code is licensed under the MIT license found in the
37
+ * LICENSE file in the root directory of this source tree.
38
+ */
39
+ s((function(t,e){}));var k=s((function(t){t.exports=w})),C=e.useLayoutEffect;function P(t){var e=o.useRef();return e.current||(e.current={v:t()}),e.current.v}function R(t,e){var r=P((function(){return"function"==typeof t?t():t})),u=e.context,a=e.guards,o=e.actions,c=e.activities,s=e.services,f=e.delays;e.state;var l=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}(e,["context","guards","actions","activities","services","delays","state"]),v=P((function(){var t={context:u,guards:a,actions:o,activities:c,services:s,delays:f},e=r.withConfig(t,(function(){return i(i({},r.context),u)}));return n.interpret(e,l)}));return C((function(){Object.assign(v.machine.options.actions,o),Object.assign(v.machine.options.guards,a),Object.assign(v.machine.options.activities,c),Object.assign(v.machine.options.services,s),Object.assign(v.machine.options.delays,f)}),[o,a,c,s,f]),v}function I(t){return t}function V(t){return"state"in t}function M(t){return"deferred"in t}function N(t){return"getSnapshot"in t?t.getSnapshot():V(t)?t.state:void 0}function _(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}var q=function(t,e){return t===e};t.shallowEqual=function(t,e){if(_(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var u=0;u<n.length;u++)if(!Object.prototype.hasOwnProperty.call(e,n[u])||!_(t[n[u]],e[n[u]]))return!1;return!0},t.useActor=function(t,n){void 0===n&&(n=N);var r=e.useRef(t),u=e.useRef([]),a=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),o=e.useCallback((function(){return n(t)}),[t,n]),i=S.useSyncExternalStore(a,o,o),c=P((function(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],a=r.current;M(a)&&a.deferred?u.current.push(n):a.send(n)}}));return C((function(){for(r.current=t;u.current.length>0;){var e=u.current.shift();t.send(e)}}),[t]),[i,c]},t.useInterpret=function(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var a=c(r,2),o=a[0],i=void 0===o?{}:o,s=a[1],f=R(t,i);return e.useEffect((function(){if(s){var t=f.subscribe(n.toObserver(s));return function(){t.unsubscribe()}}}),[s]),e.useEffect((function(){var t=i.state;return f.start(t?n.State.create(t):void 0),function(){f.stop(),f.status=n.InterpreterStatus.NotStarted}}),[]),f},t.useMachine=function(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var a=c(r,1),o=a[0],i=void 0===o?{}:o,s=R(t,i),f=e.useCallback((function(){return s.status===n.InterpreterStatus.NotStarted?i.state?n.State.create(i.state):s.machine.initialState:s.state}),[s]),l=e.useCallback((function(t,e){if(s.status===n.InterpreterStatus.NotStarted)return!0;var r=void 0===e.changed&&(Object.keys(e.children).length>0||"boolean"==typeof t.changed);return!(e.changed||r)}),[s]),v=e.useCallback((function(t){return s.subscribe(t).unsubscribe}),[s]),d=k.useSyncExternalStoreWithSelector(v,f,f,I,l);return e.useEffect((function(){var t=i.state;return s.start(t?n.State.create(t):void 0),function(){s.stop(),s.status=n.InterpreterStatus.NotStarted}}),[]),[d,s.send,s]},t.useSelector=function(t,n,r,u){void 0===r&&(r=q);var a=e.useRef(null),o=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),i=e.useCallback((function(){return u?u(t):function(t,e){if("state"in(u=t)&&"machine"in u){if(0===t.status&&e.current)return e.current;var n=0!==(r=t).status?r.state:r.machine.initialState;return e.current=0===t.status?n:null,n}var r,u;return V(t)?t.state:void 0}(t,a)}),[t,u]);return k.useSyncExternalStoreWithSelector(o,i,i,n,r)},t.useSpawn=function(t){return P((function(){return n.spawnBehavior(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
package/es/fsm.d.ts CHANGED
@@ -1,20 +1,4 @@
1
- import { StateMachine, EventObject, Typestate } from '@xstate/fsm';
2
- export declare function useMachine<TContext extends object, TEvent extends EventObject = EventObject, TState extends Typestate<TContext> = {
3
- value: any;
4
- context: TContext;
5
- }>(stateMachine: StateMachine.Machine<TContext, TEvent, TState>, options?: {
6
- actions?: StateMachine.ActionMap<TContext, TEvent>;
7
- }): [
8
- StateMachine.State<TContext, TEvent, TState>,
9
- StateMachine.Service<TContext, TEvent, TState>['send'],
10
- StateMachine.Service<TContext, TEvent, TState>
11
- ];
12
- export declare function useService<TContext extends object, TEvent extends EventObject = EventObject, TState extends Typestate<TContext> = {
13
- value: any;
14
- context: TContext;
15
- }>(service: StateMachine.Service<TContext, TEvent, TState>): [
16
- StateMachine.State<TContext, TEvent, TState>,
17
- StateMachine.Service<TContext, TEvent, TState>['send'],
18
- StateMachine.Service<TContext, TEvent, TState>
19
- ];
1
+ import { MachineImplementationsFrom, ServiceFrom, StateFrom, StateMachine } from '@xstate/fsm';
2
+ export declare function useMachine<TMachine extends StateMachine.AnyMachine>(stateMachine: TMachine, options?: MachineImplementationsFrom<TMachine>): [StateFrom<TMachine>, ServiceFrom<TMachine>['send'], ServiceFrom<TMachine>];
3
+ export declare function useService<TService extends StateMachine.AnyService>(service: TService): [StateFrom<TService>, TService['send'], TService];
20
4
  //# sourceMappingURL=fsm.d.ts.map
package/es/fsm.js CHANGED
@@ -14,10 +14,14 @@ var __read = (this && this.__read) || function (o, n) {
14
14
  }
15
15
  return ar;
16
16
  };
17
- import { useState, useEffect, useMemo } from 'react';
18
- import { interpret, createMachine } from '@xstate/fsm';
19
- import { useSubscription } from 'use-subscription';
17
+ import { createMachine, interpret, InterpreterStatus } from '@xstate/fsm';
18
+ import { useCallback, useEffect, useRef, useState } from 'react';
19
+ import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
20
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
20
21
  import useConstant from './useConstant';
22
+ function identity(a) {
23
+ return a;
24
+ }
21
25
  var getServiceState = function (service) {
22
26
  var currentValue;
23
27
  service
@@ -28,6 +32,7 @@ var getServiceState = function (service) {
28
32
  return currentValue;
29
33
  };
30
34
  export function useMachine(stateMachine, options) {
35
+ var persistedStateRef = useRef();
31
36
  if (process.env.NODE_ENV !== 'production') {
32
37
  var _a = __read(useState(stateMachine), 1), initialMachine = _a[0];
33
38
  if (stateMachine !== initialMachine) {
@@ -35,39 +40,43 @@ export function useMachine(stateMachine, options) {
35
40
  'Please make sure that you pass the same Machine as argument each time.');
36
41
  }
37
42
  }
38
- var service = useConstant(function () {
39
- return interpret(createMachine(stateMachine.config, options ? options : stateMachine._options)).start();
40
- });
41
- var _b = __read(useState(function () { return getServiceState(service); }), 2), state = _b[0], setState = _b[1];
42
- useEffect(function () {
43
+ var _b = __read(useConstant(function () {
44
+ var queue = [];
45
+ var service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));
46
+ var send = service.send;
47
+ service.send = function (event) {
48
+ if (service.status === InterpreterStatus.NotStarted) {
49
+ queue.push(event);
50
+ return;
51
+ }
52
+ send(event);
53
+ persistedStateRef.current = service.state;
54
+ };
55
+ return [service, queue];
56
+ }), 2), service = _b[0], queue = _b[1];
57
+ useIsomorphicLayoutEffect(function () {
43
58
  if (options) {
44
59
  service._machine._options = options;
45
60
  }
46
61
  });
62
+ var useServiceResult = useService(service);
47
63
  useEffect(function () {
48
- service.subscribe(setState);
64
+ service.start(persistedStateRef.current);
65
+ queue.forEach(service.send);
66
+ persistedStateRef.current = service.state;
49
67
  return function () {
50
68
  service.stop();
51
69
  };
52
70
  }, []);
53
- return [state, service.send, service];
71
+ return useServiceResult;
54
72
  }
73
+ var isEqual = function (_prevState, nextState) { return nextState.changed === false; };
55
74
  export function useService(service) {
56
- var subscription = useMemo(function () {
57
- var currentState = getServiceState(service);
58
- return {
59
- getCurrentValue: function () { return currentState; },
60
- subscribe: function (callback) {
61
- var unsubscribe = service.subscribe(function (state) {
62
- if (state.changed !== false) {
63
- currentState = state;
64
- callback();
65
- }
66
- }).unsubscribe;
67
- return unsubscribe;
68
- }
69
- };
75
+ var getSnapshot = useCallback(function () { return getServiceState(service); }, [service]);
76
+ var subscribe = useCallback(function (handleStoreChange) {
77
+ var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;
78
+ return unsubscribe;
70
79
  }, [service]);
71
- var state = useSubscription(subscription);
72
- return [state, service.send, service];
80
+ var storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
81
+ return [storeSnapshot, service.send, service];
73
82
  }
package/es/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { useMachine, asEffect, asLayoutEffect } from './useMachine';
1
+ export { useMachine } from './useMachine';
2
2
  export { useActor } from './useActor';
3
3
  export { useInterpret } from './useInterpret';
4
4
  export { useSelector } from './useSelector';
5
5
  export { useSpawn } from './useSpawn';
6
+ export { shallowEqual } from './utils';
6
7
  //# sourceMappingURL=index.d.ts.map
package/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { useMachine, asEffect, asLayoutEffect } from './useMachine';
1
+ export { useMachine } from './useMachine';
2
2
  export { useActor } from './useActor';
3
3
  export { useInterpret } from './useInterpret';
4
4
  export { useSelector } from './useSelector';
5
5
  export { useSpawn } from './useSpawn';
6
+ export { shallowEqual } from './utils';
package/es/types.d.ts CHANGED
@@ -1,18 +1,7 @@
1
- import { ActionMeta, ActionObject, EventObject, State, StateConfig } from 'xstate';
1
+ import { EventObject, StateConfig } from 'xstate';
2
2
  export declare type MaybeLazy<T> = T | (() => T);
3
3
  export declare type NoInfer<T> = [T][T extends any ? 0 : any];
4
4
  export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
5
- export declare enum ReactEffectType {
6
- Effect = 1,
7
- LayoutEffect = 2
8
- }
9
- export interface ReactActionFunction<TContext, TEvent extends EventObject> {
10
- (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent>): () => void;
11
- __effect: ReactEffectType;
12
- }
13
- export interface ReactActionObject<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
14
- exec: ReactActionFunction<TContext, TEvent>;
15
- }
16
5
  export interface UseMachineOptions<TContext, TEvent extends EventObject> {
17
6
  /**
18
7
  * If provided, will be merged with machine's `context`.
@@ -24,8 +13,4 @@ export interface UseMachineOptions<TContext, TEvent extends EventObject> {
24
13
  */
25
14
  state?: StateConfig<TContext, TEvent>;
26
15
  }
27
- export declare type ActionStateTuple<TContext, TEvent extends EventObject> = [
28
- ReactActionObject<TContext, TEvent>,
29
- State<TContext, TEvent>
30
- ];
31
16
  //# sourceMappingURL=types.d.ts.map
package/es/types.js CHANGED
@@ -1,5 +1 @@
1
- export var ReactEffectType;
2
- (function (ReactEffectType) {
3
- ReactEffectType[ReactEffectType["Effect"] = 1] = "Effect";
4
- ReactEffectType[ReactEffectType["LayoutEffect"] = 2] = "LayoutEffect";
5
- })(ReactEffectType || (ReactEffectType = {}));
1
+ export {};
package/es/useActor.js CHANGED
@@ -1,31 +1,13 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
- import { useState, useRef } from 'react';
1
+ import { useRef, useCallback } from 'react';
18
2
  import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
19
3
  import useConstant from './useConstant';
4
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
20
5
  export function isActorWithState(actorRef) {
21
6
  return 'state' in actorRef;
22
7
  }
23
8
  function isDeferredActor(actorRef) {
24
9
  return 'deferred' in actorRef;
25
10
  }
26
- var noop = function () {
27
- /* ... */
28
- };
29
11
  function defaultGetSnapshot(actorRef) {
30
12
  return 'getSnapshot' in actorRef
31
13
  ? actorRef.getSnapshot()
@@ -37,7 +19,15 @@ export function useActor(actorRef, getSnapshot) {
37
19
  if (getSnapshot === void 0) { getSnapshot = defaultGetSnapshot; }
38
20
  var actorRefRef = useRef(actorRef);
39
21
  var deferredEventsRef = useRef([]);
40
- var _a = __read(useState(function () { return getSnapshot(actorRef); }), 2), current = _a[0], setCurrent = _a[1];
22
+ var subscribe = useCallback(function (handleStoreChange) {
23
+ var unsubscribe = actorRef.subscribe(handleStoreChange).unsubscribe;
24
+ return unsubscribe;
25
+ }, [actorRef]);
26
+ var boundGetSnapshot = useCallback(function () { return getSnapshot(actorRef); }, [
27
+ actorRef,
28
+ getSnapshot
29
+ ]);
30
+ var storeSnapshot = useSyncExternalStore(subscribe, boundGetSnapshot, boundGetSnapshot);
41
31
  var send = useConstant(function () { return function () {
42
32
  var args = [];
43
33
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -60,20 +50,11 @@ export function useActor(actorRef, getSnapshot) {
60
50
  }; });
61
51
  useIsomorphicLayoutEffect(function () {
62
52
  actorRefRef.current = actorRef;
63
- setCurrent(getSnapshot(actorRef));
64
- var subscription = actorRef.subscribe({
65
- next: function (emitted) { return setCurrent(emitted); },
66
- error: noop,
67
- complete: noop
68
- });
69
53
  // Dequeue deferred events from the previous deferred actorRef
70
54
  while (deferredEventsRef.current.length > 0) {
71
55
  var deferredEvent = deferredEventsRef.current.shift();
72
56
  actorRef.send(deferredEvent);
73
57
  }
74
- return function () {
75
- subscription.unsubscribe();
76
- };
77
58
  }, [actorRef]);
78
- return [current, send];
59
+ return [storeSnapshot, send];
79
60
  }
@@ -1,13 +1,14 @@
1
- import { AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, Observer, State, StateMachine } from 'xstate';
1
+ import { AnyInterpreter, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, MachineOptions, Observer, StateFrom } from 'xstate';
2
2
  import { MaybeLazy } from './types';
3
3
  import { UseMachineOptions } from './useMachine';
4
- declare type RestParams<TMachine extends StateMachine<any, any, any, any, any, any, any>> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
4
+ export declare function useIdleInterpreter(getMachine: MaybeLazy<AnyStateMachine>, options: Partial<InterpreterOptions> & Partial<UseMachineOptions<unknown, never>> & Partial<MachineOptions<unknown, never>>): AnyInterpreter;
5
+ declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
5
6
  options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>,
6
- observerOrListener?: Observer<State<TMachine['__TContext'], TMachine['__TEvent'], any, TMachine['__TTypestate'], TMachine['__TResolvedTypesMeta']>> | ((value: State<TMachine['__TContext'], TMachine['__TEvent'], any, TMachine['__TTypestate'], TMachine['__TResolvedTypesMeta']>) => void)
7
+ observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
7
8
  ] : [
8
9
  options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>,
9
- observerOrListener?: Observer<State<TMachine['__TContext'], TMachine['__TEvent'], any, TMachine['__TTypestate'], TMachine['__TResolvedTypesMeta']>> | ((value: State<TMachine['__TContext'], TMachine['__TEvent'], any, TMachine['__TTypestate'], TMachine['__TResolvedTypesMeta']>) => void)
10
+ observerOrListener?: Observer<StateFrom<TMachine>> | ((value: StateFrom<TMachine>) => void)
10
11
  ];
11
- export declare function useInterpret<TMachine extends StateMachine<any, any, any, any, any, any, any>>(getMachine: MaybeLazy<TMachine>, ...[options, observerOrListener]: RestParams<TMachine>): InterpreterFrom<TMachine>;
12
+ export declare function useInterpret<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options, observerOrListener]: RestParams<TMachine>): InterpreterFrom<TMachine>;
12
13
  export {};
13
14
  //# sourceMappingURL=useInterpret.d.ts.map
@@ -36,44 +36,23 @@ var __read = (this && this.__read) || function (o, n) {
36
36
  }
37
37
  return ar;
38
38
  };
39
- import { useState } from 'react';
39
+ import { useEffect, useState } from 'react';
40
40
  import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
41
- import { interpret, State } from 'xstate';
41
+ import { interpret, InterpreterStatus, State, toObserver } from 'xstate';
42
42
  import useConstant from './useConstant';
43
- import { useReactEffectActions } from './useReactEffectActions';
44
- // copied from core/src/utils.ts
45
- // it avoids a breaking change between this package and XState which is its peer dep
46
- function toObserver(nextHandler, errorHandler, completionHandler) {
47
- if (typeof nextHandler === 'object') {
48
- return nextHandler;
49
- }
50
- var noop = function () { return void 0; };
51
- return {
52
- next: nextHandler,
53
- error: errorHandler || noop,
54
- complete: completionHandler || noop
55
- };
56
- }
57
- export function useInterpret(getMachine) {
58
- var _a = [];
59
- for (var _i = 1; _i < arguments.length; _i++) {
60
- _a[_i - 1] = arguments[_i];
61
- }
62
- var _b = __read(_a, 2), _c = _b[0], options = _c === void 0 ? {} : _c, observerOrListener = _b[1];
43
+ export function useIdleInterpreter(getMachine, options) {
63
44
  var machine = useConstant(function () {
64
45
  return typeof getMachine === 'function' ? getMachine() : getMachine;
65
46
  });
66
47
  if (process.env.NODE_ENV !== 'production' &&
67
48
  typeof getMachine !== 'function') {
68
- var _d = __read(useState(machine), 1), initialMachine = _d[0];
49
+ var _a = __read(useState(machine), 1), initialMachine = _a[0];
69
50
  if (getMachine !== initialMachine) {
70
51
  console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\n' +
71
52
  'Please make sure that you pass the same Machine as argument each time.');
72
53
  }
73
54
  }
74
- 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"]);
75
- // it's not defined in `TypegenMachineOptions` so we can't just unpack this property here freely
76
- var activities = options.activities;
55
+ 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"]);
77
56
  var service = useConstant(function () {
78
57
  var machineConfig = {
79
58
  context: context,
@@ -84,23 +63,8 @@ export function useInterpret(getMachine) {
84
63
  delays: delays
85
64
  };
86
65
  var machineWithConfig = machine.withConfig(machineConfig, function () { return (__assign(__assign({}, machine.context), context)); });
87
- return interpret(machineWithConfig, __assign({ deferEvents: true }, interpreterOptions));
66
+ return interpret(machineWithConfig, interpreterOptions);
88
67
  });
89
- useIsomorphicLayoutEffect(function () {
90
- var sub;
91
- if (observerOrListener) {
92
- sub = service.subscribe(toObserver(observerOrListener));
93
- }
94
- return function () {
95
- sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
96
- };
97
- }, [observerOrListener]);
98
- useIsomorphicLayoutEffect(function () {
99
- service.start(rehydratedState ? State.create(rehydratedState) : undefined);
100
- return function () {
101
- service.stop();
102
- };
103
- }, []);
104
68
  // Make sure options are kept updated when they change.
105
69
  // This mutation assignment is safe because the service instance is only used
106
70
  // in one place -- this hook's caller.
@@ -111,6 +75,31 @@ export function useInterpret(getMachine) {
111
75
  Object.assign(service.machine.options.services, services);
112
76
  Object.assign(service.machine.options.delays, delays);
113
77
  }, [actions, guards, activities, services, delays]);
114
- useReactEffectActions(service);
78
+ return service;
79
+ }
80
+ export function useInterpret(getMachine) {
81
+ var _a = [];
82
+ for (var _i = 1; _i < arguments.length; _i++) {
83
+ _a[_i - 1] = arguments[_i];
84
+ }
85
+ var _b = __read(_a, 2), _c = _b[0], options = _c === void 0 ? {} : _c, observerOrListener = _b[1];
86
+ var service = useIdleInterpreter(getMachine, options);
87
+ useEffect(function () {
88
+ if (!observerOrListener) {
89
+ return;
90
+ }
91
+ var sub = service.subscribe(toObserver(observerOrListener));
92
+ return function () {
93
+ sub.unsubscribe();
94
+ };
95
+ }, [observerOrListener]);
96
+ useEffect(function () {
97
+ var rehydratedState = options.state;
98
+ service.start(rehydratedState ? State.create(rehydratedState) : undefined);
99
+ return function () {
100
+ service.stop();
101
+ service.status = InterpreterStatus.NotStarted;
102
+ };
103
+ }, []);
115
104
  return service;
116
105
  }
@@ -1,7 +1,5 @@
1
- import { ActionFunction, AreAllImplementationsAssumedToBeProvided, EventObject, InternalMachineOptions, InterpreterFrom, InterpreterOptions, StateConfig, StateFrom, StateMachine } from 'xstate';
2
- import { MaybeLazy, Prop, ReactActionFunction } from './types';
3
- export declare function asEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;
4
- export declare function asLayoutEffect<TContext, TEvent extends EventObject>(exec: ActionFunction<TContext, TEvent>): ReactActionFunction<TContext, TEvent>;
1
+ import { AnyStateMachine, AreAllImplementationsAssumedToBeProvided, EventObject, InternalMachineOptions, InterpreterFrom, InterpreterOptions, StateConfig, StateFrom } from 'xstate';
2
+ import { MaybeLazy, Prop } from './types';
5
3
  export interface UseMachineOptions<TContext, TEvent extends EventObject> {
6
4
  /**
7
5
  * If provided, will be merged with machine's `context`.
@@ -13,12 +11,12 @@ export interface UseMachineOptions<TContext, TEvent extends EventObject> {
13
11
  */
14
12
  state?: StateConfig<TContext, TEvent>;
15
13
  }
16
- declare type RestParams<TMachine extends StateMachine<any, any, any, any, any, any, any>> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
14
+ declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
17
15
  options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>
18
16
  ] : [
19
17
  options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>
20
18
  ];
21
- declare type UseMachineReturn<TMachine extends StateMachine<any, any, any, any, any, any, any>, TInterpreter = InterpreterFrom<TMachine>> = [StateFrom<TMachine>, Prop<TInterpreter, 'send'>, TInterpreter];
22
- export declare function useMachine<TMachine extends StateMachine<any, any, any, any, any, any, any>>(getMachine: MaybeLazy<TMachine>, ...[options]: RestParams<TMachine>): UseMachineReturn<TMachine>;
19
+ declare type UseMachineReturn<TMachine extends AnyStateMachine, TInterpreter = InterpreterFrom<TMachine>> = [StateFrom<TMachine>, Prop<TInterpreter, 'send'>, TInterpreter];
20
+ export declare function useMachine<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options]: RestParams<TMachine>): UseMachineReturn<TMachine>;
23
21
  export {};
24
22
  //# sourceMappingURL=useMachine.d.ts.map