@xstate/react 3.1.0 → 3.1.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.
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
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=o.default.useState,v=o.default.useEffect,d=o.default.useLayoutEffect,p=o.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,o=r[1];return d((function(){u.value=n,u.getSnapshot=e,b(u)&&o({inst:u})}),[t,n,e]),v((function(){return b(u)&&o({inst:u}),t((function(){b(u)&&o({inst:u})}))}),[t]),p(n),n},h={useSyncExternalStore:void 0!==o.default.useSyncExternalStore?o.default.useSyncExternalStore:y};
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=o.default.useState,v=o.default.useEffect,d=o.default.useLayoutEffect,p=o.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 h="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,o=r[1];return d((function(){u.value=n,u.getSnapshot=e,b(u)&&o({inst:u})}),[t,n,e]),v((function(){return b(u)&&o({inst:u}),t((function(){b(u)&&o({inst:u})}))}),[t]),p(n),n},y={useSyncExternalStore:void 0!==o.default.useSyncExternalStore?o.default.useSyncExternalStore:h};
11
11
  /**
12
12
  * @license React
13
13
  * use-sync-external-store-shim.development.js
@@ -17,7 +17,7 @@
17
17
  * This source code is licensed under the MIT license found in the
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  */
20
- s((function(t,e){}));var S=s((function(t){t.exports=h}));
20
+ s((function(t,e){}));var S=s((function(t){t.exports=y}));
21
21
  /**
22
22
  * @license React
23
23
  * use-sync-external-store-shim/with-selector.production.min.js
@@ -36,4 +36,4 @@ s((function(t,e){}));var S=s((function(t){t.exports=h}));
36
36
  * This source code is licensed under the MIT license found in the
37
37
  * LICENSE file in the root directory of this source tree.
38
38
  */
39
- s((function(t,e){}));var k=s((function(t){t.exports=w})),C=e.useLayoutEffect;function P(t){var e=a.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,o=e.guards,a=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:o,actions:a,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,a),Object.assign(v.machine.options.guards,o),Object.assign(v.machine.options.activities,c),Object.assign(v.machine.options.services,s),Object.assign(v.machine.options.delays,f)}),[a,o,c,s,f]),v}function N(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=c(r,2),a=o[0],i=void 0===a?{}:a,s=o[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}function I(t){return t}function A(t){return 0!==t.status?t.getSnapshot():t.machine.initialState}function V(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function M(t){return"state"in t&&"machine"in t}function _(t){return"state"in t}function q(t){return"deferred"in t}function D(t){return"getSnapshot"in t?M(t)?A(t):t.getSnapshot():_(t)?t.state:void 0}function W(t,n){void 0===n&&(n=D);var r=e.useRef(t),u=e.useRef([]),o=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),a=e.useCallback((function(){return n(t)}),[t,n]),i=S.useSyncExternalStore(o,a,a),c=P((function(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=r.current;q(o)&&o.deferred?u.current.push(n):o.send(n)}}));return C((function(){for(r.current=t;u.current.length>0;){var e=u.current.shift();t.send(e)}}),[t]),[i,c]}var L=function(t,e){return t===e};function T(t,n,r,u){void 0===r&&(r=L);var o=e.useRef(null),a=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),i=e.useCallback((function(){return u?u(t):function(t,e){if(M(t)){if(0===t.status&&e.current)return e.current;var n=A(t);return e.current=0===t.status?n:null,n}return _(t)?t.state:void 0}(t,o)}),[t,u]);return k.useSyncExternalStoreWithSelector(a,i,i,n,r)}t.createActorContext=function(t){var e=a.createContext(null),n=e.Provider;function r(e){var r=e.children,u=e.machine,o=N(void 0===u?t:u);return a.createElement(n,{value:o},r)}function u(){var t=a.useContext(e);if(!t)throw new Error('You used a hook from "'.concat(r.displayName,"\" but it's not inside a <").concat(r.displayName,"> component."));return t}return r.displayName="ActorProvider(".concat(t.id,")"),{Provider:r,useActorRef:u,useActor:function(){return W(u())},useSelector:function(t,e){return T(u(),t,e)}}},t.shallowEqual=function(t,e){if(V(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])||!V(t[n[u]],e[n[u]]))return!1;return!0},t.useActor=W,t.useInterpret=N,t.useMachine=function(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=c(r,1),a=o[0],i=void 0===a?{}:a,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.getSnapshot()}),[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=T,t.useSpawn=function(t){return P((function(){return n.spawnBehavior(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
39
+ s((function(t,e){}));var k=s((function(t){t.exports=w})),C=e.useLayoutEffect;function P(t){var e=a.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,o=e.guards,a=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:o,actions:a,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,a),Object.assign(v.machine.options.guards,o),Object.assign(v.machine.options.activities,c),Object.assign(v.machine.options.services,s),Object.assign(v.machine.options.delays,f)}),[a,o,c,s,f]),v}function N(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=c(r,2),a=o[0],i=void 0===a?{}:a,s=o[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}function I(t){return 0!==t.status?t.getSnapshot():t.machine.initialState}function A(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function V(t){return"state"in t&&"machine"in t}function M(t,e,r){if(t.status===n.InterpreterStatus.NotStarted)return!0;var u=void 0===r.changed&&(Object.keys(r.children).length>0||"boolean"==typeof e.changed);return!(r.changed||u)}function W(t){return t}function _(t){return t}function q(t){return"state"in t}function D(t){return"deferred"in t}function L(t){return"getSnapshot"in t?V(t)?I(t):t.getSnapshot():q(t)?t.state:void 0}function T(t,n){void 0===n&&(n=L);var r=e.useRef(t),u=e.useRef([]),o=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),a=e.useCallback((function(){return n(t)}),[t,n]),i=e.useCallback((function(e,n){return V(t)?M(t,e,n):e===n}),[t]),c=k.useSyncExternalStoreWithSelector(o,a,a,_,i),s=P((function(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=r.current;D(o)&&o.deferred?u.current.push(n):o.send(n)}}));return C((function(){for(r.current=t;u.current.length>0;){var e=u.current.shift();t.send(e)}}),[t]),[c,s]}var X=function(t,e){return t===e};function z(t,n,r,u){void 0===r&&(r=X);var o=e.useRef(null),a=e.useCallback((function(e){return t.subscribe(e).unsubscribe}),[t]),i=e.useCallback((function(){return u?u(t):function(t,e){if(V(t)){if(0===t.status&&e.current)return e.current;var n=I(t);return e.current=0===t.status?n:null,n}return q(t)?t.state:void 0}(t,o)}),[t,u]);return k.useSyncExternalStoreWithSelector(a,i,i,n,r)}t.createActorContext=function(t){var e=a.createContext(null),n=e.Provider;function r(e){var r=e.children,u=e.machine,o=N(void 0===u?t:u);return a.createElement(n,{value:o},r)}function u(){var t=a.useContext(e);if(!t)throw new Error('You used a hook from "'.concat(r.displayName,"\" but it's not inside a <").concat(r.displayName,"> component."));return t}return r.displayName="ActorProvider(".concat(t.id,")"),{Provider:r,useActorRef:u,useActor:function(){return T(u())},useSelector:function(t,e){return z(u(),t,e)}}},t.shallowEqual=function(t,e){if(A(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])||!A(t[n[u]],e[n[u]]))return!1;return!0},t.useActor=T,t.useInterpret=N,t.useMachine=function(t){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var o=c(r,1),a=o[0],i=void 0===a?{}:a,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.getSnapshot()}),[s]),l=e.useCallback((function(t,e){return M(s,t,e)}),[s]),v=e.useCallback((function(t){return s.subscribe(t).unsubscribe}),[s]),d=k.useSyncExternalStoreWithSelector(v,f,f,W,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=z,t.useSpawn=function(t){return P((function(){return n.spawnBehavior(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
package/es/useActor.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { useRef, useCallback } from 'react';
2
2
  import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
3
3
  import useConstant from './useConstant';
4
- import { useSyncExternalStore } from 'use-sync-external-store/shim';
5
- import { getServiceSnapshot, isService } from './utils';
4
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
5
+ import { getServiceSnapshot, isInterpreterStateEqual, isService } from './utils';
6
+ function identity(a) {
7
+ return a;
8
+ }
6
9
  export function isActorWithState(actorRef) {
7
10
  return 'state' in actorRef;
8
11
  }
@@ -26,11 +29,14 @@ export function useActor(actorRef, getSnapshot) {
26
29
  var unsubscribe = actorRef.subscribe(handleStoreChange).unsubscribe;
27
30
  return unsubscribe;
28
31
  }, [actorRef]);
29
- var boundGetSnapshot = useCallback(function () { return getSnapshot(actorRef); }, [
30
- actorRef,
31
- getSnapshot
32
- ]);
33
- var storeSnapshot = useSyncExternalStore(subscribe, boundGetSnapshot, boundGetSnapshot);
32
+ var boundGetSnapshot = useCallback(function () { return getSnapshot(actorRef); }, [actorRef, getSnapshot]);
33
+ var isEqual = useCallback(function (prevState, nextState) {
34
+ if (isService(actorRef)) {
35
+ return isInterpreterStateEqual(actorRef, prevState, nextState);
36
+ }
37
+ return prevState === nextState;
38
+ }, [actorRef]);
39
+ var storeSnapshot = useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, identity, isEqual);
34
40
  var send = useConstant(function () { return function () {
35
41
  var args = [];
36
42
  for (var _i = 0; _i < arguments.length; _i++) {
package/es/useMachine.js CHANGED
@@ -18,6 +18,7 @@ import { useCallback, useEffect } from 'react';
18
18
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
19
19
  import { InterpreterStatus, State } from 'xstate';
20
20
  import { useIdleInterpreter } from './useInterpret';
21
+ import { isInterpreterStateEqual } from './utils';
21
22
  function identity(a) {
22
23
  return a;
23
24
  }
@@ -39,18 +40,7 @@ export function useMachine(getMachine) {
39
40
  return service.getSnapshot();
40
41
  }, [service]);
41
42
  var isEqual = useCallback(function (prevState, nextState) {
42
- if (service.status === InterpreterStatus.NotStarted) {
43
- return true;
44
- }
45
- // Only change the current state if:
46
- // - the incoming state is the "live" initial state (since it might have new actors)
47
- // - OR the incoming state actually changed.
48
- //
49
- // The "live" initial state will have .changed === undefined.
50
- var initialStateChanged = nextState.changed === undefined &&
51
- (Object.keys(nextState.children).length > 0 ||
52
- typeof prevState.changed === 'boolean');
53
- return !(nextState.changed || initialStateChanged);
43
+ return isInterpreterStateEqual(service, prevState, nextState);
54
44
  }, [service]);
55
45
  var subscribe = useCallback(function (handleStoreChange) {
56
46
  var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;
package/es/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Interpreter } from 'xstate';
1
+ import { AnyInterpreter, AnyState, Interpreter } from 'xstate';
2
2
  export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
3
3
  export declare function getServiceSnapshot<TService extends Interpreter<any, any, any, any>>(service: TService): TService['state'];
4
4
  export declare function shallowEqual(objA: any, objB: any): boolean;
5
5
  export declare function isService(actor: any): actor is Interpreter<any, any, any, any>;
6
+ export declare function isInterpreterStateEqual(service: AnyInterpreter, prevState: AnyState, nextState: AnyState): boolean;
6
7
  //# sourceMappingURL=utils.d.ts.map
package/es/utils.js CHANGED
@@ -25,6 +25,7 @@ var __values = (this && this.__values) || function(o) {
25
25
  };
26
26
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
27
  };
28
+ import { InterpreterStatus } from 'xstate';
28
29
  export function partition(items, predicate) {
29
30
  var e_1, _a;
30
31
  var _b = __read([[], []], 2), truthy = _b[0], falsy = _b[1];
@@ -86,3 +87,17 @@ export function shallowEqual(objA, objB) {
86
87
  export function isService(actor) {
87
88
  return 'state' in actor && 'machine' in actor;
88
89
  }
90
+ export function isInterpreterStateEqual(service, prevState, nextState) {
91
+ if (service.status === InterpreterStatus.NotStarted) {
92
+ return true;
93
+ }
94
+ // Only change the current state if:
95
+ // - the incoming state is the "live" initial state (since it might have new actors)
96
+ // - OR the incoming state actually changed.
97
+ //
98
+ // The "live" initial state will have .changed === undefined.
99
+ var initialStateChanged = nextState.changed === undefined &&
100
+ (Object.keys(nextState.children).length > 0 ||
101
+ typeof prevState.changed === 'boolean');
102
+ return !(nextState.changed || initialStateChanged);
103
+ }
package/lib/useActor.js CHANGED
@@ -4,8 +4,11 @@ exports.useActor = exports.isActorWithState = void 0;
4
4
  var react_1 = require("react");
5
5
  var use_isomorphic_layout_effect_1 = require("use-isomorphic-layout-effect");
6
6
  var useConstant_1 = require("./useConstant");
7
- var shim_1 = require("use-sync-external-store/shim");
7
+ var with_selector_1 = require("use-sync-external-store/shim/with-selector");
8
8
  var utils_1 = require("./utils");
9
+ function identity(a) {
10
+ return a;
11
+ }
9
12
  function isActorWithState(actorRef) {
10
13
  return 'state' in actorRef;
11
14
  }
@@ -30,11 +33,14 @@ function useActor(actorRef, getSnapshot) {
30
33
  var unsubscribe = actorRef.subscribe(handleStoreChange).unsubscribe;
31
34
  return unsubscribe;
32
35
  }, [actorRef]);
33
- var boundGetSnapshot = (0, react_1.useCallback)(function () { return getSnapshot(actorRef); }, [
34
- actorRef,
35
- getSnapshot
36
- ]);
37
- var storeSnapshot = (0, shim_1.useSyncExternalStore)(subscribe, boundGetSnapshot, boundGetSnapshot);
36
+ var boundGetSnapshot = (0, react_1.useCallback)(function () { return getSnapshot(actorRef); }, [actorRef, getSnapshot]);
37
+ var isEqual = (0, react_1.useCallback)(function (prevState, nextState) {
38
+ if ((0, utils_1.isService)(actorRef)) {
39
+ return (0, utils_1.isInterpreterStateEqual)(actorRef, prevState, nextState);
40
+ }
41
+ return prevState === nextState;
42
+ }, [actorRef]);
43
+ var storeSnapshot = (0, with_selector_1.useSyncExternalStoreWithSelector)(subscribe, boundGetSnapshot, boundGetSnapshot, identity, isEqual);
38
44
  var send = (0, useConstant_1.default)(function () { return function () {
39
45
  var args = [];
40
46
  for (var _i = 0; _i < arguments.length; _i++) {
package/lib/useMachine.js CHANGED
@@ -21,6 +21,7 @@ var react_1 = require("react");
21
21
  var with_selector_1 = require("use-sync-external-store/shim/with-selector");
22
22
  var xstate_1 = require("xstate");
23
23
  var useInterpret_1 = require("./useInterpret");
24
+ var utils_1 = require("./utils");
24
25
  function identity(a) {
25
26
  return a;
26
27
  }
@@ -42,18 +43,7 @@ function useMachine(getMachine) {
42
43
  return service.getSnapshot();
43
44
  }, [service]);
44
45
  var isEqual = (0, react_1.useCallback)(function (prevState, nextState) {
45
- if (service.status === xstate_1.InterpreterStatus.NotStarted) {
46
- return true;
47
- }
48
- // Only change the current state if:
49
- // - the incoming state is the "live" initial state (since it might have new actors)
50
- // - OR the incoming state actually changed.
51
- //
52
- // The "live" initial state will have .changed === undefined.
53
- var initialStateChanged = nextState.changed === undefined &&
54
- (Object.keys(nextState.children).length > 0 ||
55
- typeof prevState.changed === 'boolean');
56
- return !(nextState.changed || initialStateChanged);
46
+ return (0, utils_1.isInterpreterStateEqual)(service, prevState, nextState);
57
47
  }, [service]);
58
48
  var subscribe = (0, react_1.useCallback)(function (handleStoreChange) {
59
49
  var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Interpreter } from 'xstate';
1
+ import { AnyInterpreter, AnyState, Interpreter } from 'xstate';
2
2
  export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
3
3
  export declare function getServiceSnapshot<TService extends Interpreter<any, any, any, any>>(service: TService): TService['state'];
4
4
  export declare function shallowEqual(objA: any, objB: any): boolean;
5
5
  export declare function isService(actor: any): actor is Interpreter<any, any, any, any>;
6
+ export declare function isInterpreterStateEqual(service: AnyInterpreter, prevState: AnyState, nextState: AnyState): boolean;
6
7
  //# sourceMappingURL=utils.d.ts.map
package/lib/utils.js CHANGED
@@ -27,7 +27,8 @@ var __values = (this && this.__values) || function(o) {
27
27
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.isService = exports.shallowEqual = exports.getServiceSnapshot = exports.partition = void 0;
30
+ exports.isInterpreterStateEqual = exports.isService = exports.shallowEqual = exports.getServiceSnapshot = exports.partition = void 0;
31
+ var xstate_1 = require("xstate");
31
32
  function partition(items, predicate) {
32
33
  var e_1, _a;
33
34
  var _b = __read([[], []], 2), truthy = _b[0], falsy = _b[1];
@@ -93,3 +94,18 @@ function isService(actor) {
93
94
  return 'state' in actor && 'machine' in actor;
94
95
  }
95
96
  exports.isService = isService;
97
+ function isInterpreterStateEqual(service, prevState, nextState) {
98
+ if (service.status === xstate_1.InterpreterStatus.NotStarted) {
99
+ return true;
100
+ }
101
+ // Only change the current state if:
102
+ // - the incoming state is the "live" initial state (since it might have new actors)
103
+ // - OR the incoming state actually changed.
104
+ //
105
+ // The "live" initial state will have .changed === undefined.
106
+ var initialStateChanged = nextState.changed === undefined &&
107
+ (Object.keys(nextState.children).length > 0 ||
108
+ typeof prevState.changed === 'boolean');
109
+ return !(nextState.changed || initialStateChanged);
110
+ }
111
+ exports.isInterpreterStateEqual = isInterpreterStateEqual;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/react",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "XState tools for React",
5
5
  "keywords": [
6
6
  "state",
@@ -54,7 +54,7 @@
54
54
  "peerDependencies": {
55
55
  "@xstate/fsm": "^2.0.0",
56
56
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
57
- "xstate": "^4.35.3"
57
+ "xstate": "^4.35.4"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "@xstate/fsm": {