@xstate/react
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -39,2 +39,2 @@ !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 o=r(e),a=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,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.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 a}function s(t){var e={exports:{}};return t(e,e.exports),e.exports | ||
*/ | ||
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})})); | ||
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){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=c(e,2),u=r[0],o=void 0===u?{}:u,i=r[1],s=a.createContext(null),f=s.Provider;function l(e){var n=e.children,r=e.machine,u=N(void 0===r?t:r,o,i);return a.createElement(f,{value:u},n)}function v(){var t=a.useContext(s);if(!t)throw new Error('You used a hook from "'.concat(l.displayName,"\" but it's not inside a <").concat(l.displayName,"> component."));return t}function d(){return T(v())}function p(t,e){return z(v(),t,e)}return l.displayName="ActorProvider(".concat(t.id,")"),{Provider:l,useActorRef:v,useActor:d,useSelector:p}},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})})); |
import * as React from 'react'; | ||
import { RestParams } from './useInterpret'; | ||
import { useActor as useActorUnbound } from './useActor'; | ||
import { ActorRefFrom, AnyStateMachine, EmittedFrom } from 'xstate'; | ||
export declare function createActorContext<TMachine extends AnyStateMachine>(machine: TMachine): { | ||
export declare function createActorContext<TMachine extends AnyStateMachine>(machine: TMachine, ...[options, observerOrListener]: RestParams<TMachine>): { | ||
useActor: () => ReturnType<typeof useActorUnbound<ActorRefFrom<TMachine>>>; | ||
@@ -6,0 +7,0 @@ useSelector: <T>(selector: (snapshot: EmittedFrom<TMachine>) => T, compare?: (a: T, b: T) => boolean) => T; |
@@ -0,1 +1,17 @@ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
import * as React from 'react'; | ||
@@ -6,2 +22,7 @@ import { useInterpret } from './useInterpret'; | ||
export function createActorContext(machine) { | ||
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 ReactContext = React.createContext(null); | ||
@@ -11,3 +32,3 @@ var OriginalProvider = ReactContext.Provider; | ||
var children = _a.children, _b = _a.machine, providedMachine = _b === void 0 ? machine : _b; | ||
var actor = useInterpret(providedMachine); | ||
var actor = useInterpret(providedMachine, options, observerOrListener); | ||
return React.createElement(OriginalProvider, { value: actor }, children); | ||
@@ -14,0 +35,0 @@ } |
@@ -5,3 +5,3 @@ import { AnyInterpreter, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, MachineOptions, Observer, StateFrom } from 'xstate'; | ||
export declare function useIdleInterpreter(getMachine: MaybeLazy<AnyStateMachine>, options: Partial<InterpreterOptions> & Partial<UseMachineOptions<unknown, never>> & Partial<MachineOptions<unknown, never>>): AnyInterpreter; | ||
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [ | ||
export 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>, | ||
@@ -14,3 +14,2 @@ 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 |
import * as React from 'react'; | ||
import { RestParams } from './useInterpret'; | ||
import { useActor as useActorUnbound } from './useActor'; | ||
import { ActorRefFrom, AnyStateMachine, EmittedFrom } from 'xstate'; | ||
export declare function createActorContext<TMachine extends AnyStateMachine>(machine: TMachine): { | ||
export declare function createActorContext<TMachine extends AnyStateMachine>(machine: TMachine, ...[options, observerOrListener]: RestParams<TMachine>): { | ||
useActor: () => ReturnType<typeof useActorUnbound<ActorRefFrom<TMachine>>>; | ||
@@ -6,0 +7,0 @@ useSelector: <T>(selector: (snapshot: EmittedFrom<TMachine>) => T, compare?: (a: T, b: T) => boolean) => T; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,2 +25,7 @@ exports.createActorContext = void 0; | ||
function createActorContext(machine) { | ||
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 ReactContext = React.createContext(null); | ||
@@ -14,3 +35,3 @@ var OriginalProvider = ReactContext.Provider; | ||
var children = _a.children, _b = _a.machine, providedMachine = _b === void 0 ? machine : _b; | ||
var actor = (0, useInterpret_1.useInterpret)(providedMachine); | ||
var actor = (0, useInterpret_1.useInterpret)(providedMachine, options, observerOrListener); | ||
return React.createElement(OriginalProvider, { value: actor }, children); | ||
@@ -17,0 +38,0 @@ } |
@@ -5,3 +5,3 @@ import { AnyInterpreter, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineOptions, InterpreterFrom, InterpreterOptions, MachineOptions, Observer, StateFrom } from 'xstate'; | ||
export declare function useIdleInterpreter(getMachine: MaybeLazy<AnyStateMachine>, options: Partial<InterpreterOptions> & Partial<UseMachineOptions<unknown, never>> & Partial<MachineOptions<unknown, never>>): AnyInterpreter; | ||
declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [ | ||
export 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>, | ||
@@ -14,3 +14,2 @@ 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 |
{ | ||
"name": "@xstate/react", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "XState tools for React", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80150
1453