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

@xstate/react

Package Overview
Dependencies
Maintainers
1
Versions
79
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.3.3 to 1.3.4

6

CHANGELOG.md
# Changelog
## 1.3.4
### Patch Changes
- [`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.
## 1.3.3

@@ -4,0 +10,0 @@

2

dist/xstate-react.umd.min.js

@@ -15,2 +15,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";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var r,u=function(){return(u=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,c=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=c.next()).done;)o.push(r.value)}catch(t){u={error:t}}finally{try{r&&!r.done&&(n=c.return)&&n.call(c)}finally{if(u)throw u.error}}return o}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}!function(t){t[t.Effect=1]="Effect",t[t.LayoutEffect=2]="LayoutEffect"}(r||(r={}));var i=e.useLayoutEffect;function f(t){var n=e.useRef();return n.current||(n.current={v:t()}),n.current.v}function a(t,e){var n,r,u=c([[],[]],2),o=u[0],i=u[1];try{for(var f=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),a=f.next();!a.done;a=f.next()){var s=a.value;e(s)?o.push(s):i.push(s)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}return[o,i]}function s(t,e){(0,t.exec)(e.context,e._event.data,{action:t,state:e,_event:e._event})()}function l(t,l,v){void 0===l&&(l={});var d=f((function(){return"function"==typeof t?t():t})),p=l.context,y=l.guards,b=l.actions,h=l.activities,g=l.services,m=l.delays,x=l.state,O=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}(l,["context","guards","actions","activities","services","delays","state"]),S=f((function(){var t={context:p,guards:y,actions:b,activities:h,services:g,delays:m},e=d.withConfig(t,u(u({},d.context),p));return n.interpret(e,u({deferEvents:!0},O))}));return i((function(){var t;return v&&(t=S.subscribe(function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(v))),function(){null==t||t.unsubscribe()}}),[v]),i((function(){return S.start(x?n.State.create(x):void 0),function(){S.stop()}}),[]),i((function(){Object.assign(S.machine.options.actions,b)}),[b]),i((function(){Object.assign(S.machine.options.services,g)}),[g]),function(t){var n=e.useRef([]),u=e.useRef([]);i((function(){var e=t.subscribe((function(t){var e,i;if(t.actions.length){var f=c(a(t.actions.filter((function(t){return"function"==typeof t.exec&&"__effect"in t.exec})),(function(t){return t.exec.__effect===r.Effect})),2),s=f[0],l=f[1];(e=n.current).push.apply(e,o(s.map((function(e){return[e,t]})))),(i=u.current).push.apply(i,o(l.map((function(e){return[e,t]}))))}}));return function(){e.unsubscribe()}}),[]),i((function(){for(;u.current.length;){var t=c(u.current.shift(),2);s(t[0],t[1])}})),e.useEffect((function(){for(;n.current.length;){var t=c(n.current.shift(),2);s(t[0],t[1])}}))}(S),S}function v(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,o(e))}};return Object.defineProperties(n,{name:{value:"effect:"+t.name},__effect:{value:e}}),n}function d(t){return"state"in t}var p=function(){};function y(t,n){void 0===n&&(n=function(t){return d(t)?t.state:void 0});var r=e.useRef(t),u=e.useRef([]),o=c(e.useState((function(){return n(t)})),2),a=o[0],s=o[1],l=f((function(){return function(t){var e=r.current;(function(t){return"deferred"in t})(e)&&e.deferred?u.current.push(t):e.send(t)}}));return i((function(){r.current=t,s(n(t));for(var e=t.subscribe({next:function(t){return s(t)},error:p,complete:p});u.current.length>0;){var c=u.current.shift();t.send(c)}return function(){e.unsubscribe()}}),[t]),[a,l]}function b(t){return 0!==("status"in t?t.status:t._status)?t.state:t.machine.initialState}var h=function(t,e){return t===e},g=function(t){return"state"in(e=t)&&"machine"in e?b(t):d(t)?t.state:void 0;var e};t.asEffect=function(t){return v(t,r.Effect)},t.asLayoutEffect=function(t){return v(t,r.LayoutEffect)},t.useActor=y,t.useInterpret=l,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)&&a(t)}),[]),o=l(t,r,u),i=c(e.useState((function(){var t=o.machine.initialState;return r.state?n.State.create(r.state):t})),2),f=i[0],a=i[1];return[f,o.send,o]},t.useSelector=function(t,n,r,u){void 0===r&&(r=h),void 0===u&&(u=g);var o=c(e.useState((function(){return n(u(t))})),2),i=o[0],f=o[1],a=e.useRef(i);return e.useEffect((function(){var e=function(t){r(a.current,t)||(f(t),a.current=t)},c=n(u(t));e(c);var o=t.subscribe((function(t){var r=n(t);e(r)}));return function(){return o.unsubscribe()}}),[n,r]),i},t.useService=function(t){return[c(y(t,b),1)[0],t.send]},Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var r,u=function(){return(u=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 o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,u,o=n.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)i.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 i}function i(t,e){for(var n=0,r=e.length,u=t.length;n<r;n++,u++)t[u]=e[n];return t}!function(t){t[t.Effect=1]="Effect",t[t.LayoutEffect=2]="LayoutEffect"}(r||(r={}));var c=e.useLayoutEffect;function f(t){var n=e.useRef();return n.current||(n.current={v:t()}),n.current.v}function a(t,e){var n,r,u=o([[],[]],2),i=u[0],c=u[1];try{for(var f=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),a=f.next();!a.done;a=f.next()){var s=a.value;e(s)?i.push(s):c.push(s)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}return[i,c]}function s(t,e){(0,t.exec)(e.context,e._event.data,{action:t,state:e,_event:e._event})()}function l(t,l,v){void 0===l&&(l={});var p=f((function(){return"function"==typeof t?t():t})),d=l.context,y=l.guards,h=l.actions,b=l.activities,g=l.services,m=l.delays,x=l.state,S=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}(l,["context","guards","actions","activities","services","delays","state"]),O=f((function(){var t={context:d,guards:y,actions:h,activities:b,services:g,delays:m},e=p.withConfig(t,u(u({},p.context),d));return n.interpret(e,u({deferEvents:!0},S))}));return c((function(){var t;return v&&(t=O.subscribe(function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(v))),function(){null==t||t.unsubscribe()}}),[v]),c((function(){return O.start(x?n.State.create(x):void 0),function(){O.stop()}}),[]),c((function(){Object.assign(O.machine.options.actions,h)}),[h]),c((function(){Object.assign(O.machine.options.services,g)}),[g]),function(t){var n=e.useRef([]),u=e.useRef([]);c((function(){var e=t.subscribe((function(t){var e,c;if(t.actions.length){var f=o(a(t.actions.filter((function(t){return"function"==typeof t.exec&&"__effect"in t.exec})),(function(t){return t.exec.__effect===r.Effect})),2),s=f[0],l=f[1];(e=n.current).push.apply(e,i([],o(s.map((function(e){return[e,t]}))))),(c=u.current).push.apply(c,i([],o(l.map((function(e){return[e,t]})))))}}));return function(){e.unsubscribe()}}),[]),c((function(){for(;u.current.length;){var t=o(u.current.shift(),2);s(t[0],t[1])}})),e.useEffect((function(){for(;n.current.length;){var t=o(n.current.shift(),2);s(t[0],t[1])}}))}(O),O}function v(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,i([],o(e)))}};return Object.defineProperties(n,{name:{value:"effect:"+t.name},__effect:{value:e}}),n}function p(t){return"state"in t}var d=function(){};function y(t){return p(t)?t.state:"getSnapshot"in t?t.getSnapshot():void 0}function h(t,n){void 0===n&&(n=y);var r=e.useRef(t),u=e.useRef([]),i=o(e.useState((function(){return n(t)})),2),a=i[0],s=i[1],l=f((function(){return function(t){var e=r.current;(function(t){return"deferred"in t})(e)&&e.deferred?u.current.push(t):e.send(t)}}));return c((function(){r.current=t,s(n(t));for(var e=t.subscribe({next:function(t){return s(t)},error:d,complete:d});u.current.length>0;){var o=u.current.shift();t.send(o)}return function(){e.unsubscribe()}}),[t]),[a,l]}function b(t){return 0!==("status"in t?t.status:t._status)?t.state:t.machine.initialState}var g=function(t,e){return t===e},m=function(t){return"state"in(e=t)&&"machine"in e?b(t):p(t)?t.state:void 0;var e};t.asEffect=function(t){return v(t,r.Effect)},t.asLayoutEffect=function(t){return v(t,r.LayoutEffect)},t.useActor=h,t.useInterpret=l,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)&&a(t)}),[]),i=l(t,r,u),c=o(e.useState((function(){var t=i.machine.initialState;return r.state?n.State.create(r.state):t})),2),f=c[0],a=c[1];return[f,i.send,i]},t.useSelector=function(t,n,r,u){void 0===r&&(r=g),void 0===u&&(u=m);var i=o(e.useState((function(){return n(u(t))})),2),c=i[0],f=i[1],a=e.useRef(c);return e.useEffect((function(){var e=function(t){r(a.current,t)||(f(t),a.current=t)},o=n(u(t));e(o);var i=t.subscribe((function(t){var r=n(t);e(r)}));return function(){return i.unsubscribe()}}),[n,r]),c},t.useService=function(t){return[o(h(t,b),1)[0],t.send]},Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -7,6 +7,6 @@ import { Sender } from './types';

declare type EventOfActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<infer TEvent, any> ? TEvent : never;
declare type EmittedOfActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<any, infer TEmitted> ? TEmitted : never;
export declare function useActor<TActor extends ActorRef<any, any>>(actorRef: TActor, getSnapshot?: (actor: TActor) => EmittedOfActorRef<TActor>): [EmittedOfActorRef<TActor>, Sender<EventOfActorRef<TActor>>];
declare type EmittedFromActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<any, infer TEmitted> ? TEmitted : never;
export declare function useActor<TActor extends ActorRef<any, any>>(actorRef: TActor, getSnapshot?: (actor: TActor) => EmittedFromActorRef<TActor>): [EmittedFromActorRef<TActor>, Sender<EventOfActorRef<TActor>>];
export declare function useActor<TEvent extends EventObject, TEmitted>(actorRef: ActorRef<TEvent, TEmitted>, getSnapshot?: (actor: ActorRef<TEvent, TEmitted>) => TEmitted): [TEmitted, Sender<TEvent>];
export {};
//# sourceMappingURL=useActor.d.ts.map

@@ -29,6 +29,11 @@ var __read = (this && this.__read) || function (o, n) {

};
function defaultGetSnapshot(actorRef) {
return isActorWithState(actorRef)
? actorRef.state
: 'getSnapshot' in actorRef
? actorRef.getSnapshot()
: undefined;
}
export function useActor(actorRef, getSnapshot) {
if (getSnapshot === void 0) { getSnapshot = function (a) {
return isActorWithState(a) ? a.state : undefined;
}; }
if (getSnapshot === void 0) { getSnapshot = defaultGetSnapshot; }
var actorRefRef = useRef(actorRef);

@@ -35,0 +40,0 @@ var deferredEventsRef = useRef([]);

@@ -17,5 +17,6 @@ var __read = (this && this.__read) || function (o, n) {

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -34,3 +35,3 @@ import { useCallback, useState } from 'react';

return function () {
return exec.apply(void 0, __spread(args));
return exec.apply(void 0, __spreadArray([], __read(args)));
};

@@ -37,0 +38,0 @@ };

@@ -17,5 +17,6 @@ var __read = (this && this.__read) || function (o, n) {

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -49,4 +50,4 @@ import { useEffect, useRef } from 'react';

}), 2), effectActions = _c[0], layoutEffectActions = _c[1];
(_a = effectActionsRef.current).push.apply(_a, __spread(effectActions.map(function (effectAction) { return [effectAction, currentState]; })));
(_b = layoutEffectActionsRef.current).push.apply(_b, __spread(layoutEffectActions.map(function (layoutEffectAction) { return [layoutEffectAction, currentState]; })));
(_a = effectActionsRef.current).push.apply(_a, __spreadArray([], __read(effectActions.map(function (effectAction) { return [effectAction, currentState]; }))));
(_b = layoutEffectActionsRef.current).push.apply(_b, __spreadArray([], __read(layoutEffectActions.map(function (layoutEffectAction) { return [layoutEffectAction, currentState]; }))));
}

@@ -53,0 +54,0 @@ });

@@ -7,6 +7,6 @@ import { Sender } from './types';

declare type EventOfActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<infer TEvent, any> ? TEvent : never;
declare type EmittedOfActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<any, infer TEmitted> ? TEmitted : never;
export declare function useActor<TActor extends ActorRef<any, any>>(actorRef: TActor, getSnapshot?: (actor: TActor) => EmittedOfActorRef<TActor>): [EmittedOfActorRef<TActor>, Sender<EventOfActorRef<TActor>>];
declare type EmittedFromActorRef<TActor extends ActorRef<any, any>> = TActor extends ActorRef<any, infer TEmitted> ? TEmitted : never;
export declare function useActor<TActor extends ActorRef<any, any>>(actorRef: TActor, getSnapshot?: (actor: TActor) => EmittedFromActorRef<TActor>): [EmittedFromActorRef<TActor>, Sender<EventOfActorRef<TActor>>];
export declare function useActor<TEvent extends EventObject, TEmitted>(actorRef: ActorRef<TEvent, TEmitted>, getSnapshot?: (actor: ActorRef<TEvent, TEmitted>) => TEmitted): [TEmitted, Sender<TEvent>];
export {};
//# sourceMappingURL=useActor.d.ts.map

@@ -33,6 +33,11 @@ "use strict";

};
function defaultGetSnapshot(actorRef) {
return isActorWithState(actorRef)
? actorRef.state
: 'getSnapshot' in actorRef
? actorRef.getSnapshot()
: undefined;
}
function useActor(actorRef, getSnapshot) {
if (getSnapshot === void 0) { getSnapshot = function (a) {
return isActorWithState(a) ? a.state : undefined;
}; }
if (getSnapshot === void 0) { getSnapshot = defaultGetSnapshot; }
var actorRefRef = react_1.useRef(actorRef);

@@ -39,0 +44,0 @@ var deferredEventsRef = react_1.useRef([]);

@@ -18,5 +18,6 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -37,3 +38,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

return function () {
return exec.apply(void 0, __spread(args));
return exec.apply(void 0, __spreadArray([], __read(args)));
};

@@ -40,0 +41,0 @@ };

@@ -18,5 +18,6 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -52,4 +53,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

}), 2), effectActions = _c[0], layoutEffectActions = _c[1];
(_a = effectActionsRef.current).push.apply(_a, __spread(effectActions.map(function (effectAction) { return [effectAction, currentState]; })));
(_b = layoutEffectActionsRef.current).push.apply(_b, __spread(layoutEffectActions.map(function (layoutEffectAction) { return [layoutEffectAction, currentState]; })));
(_a = effectActionsRef.current).push.apply(_a, __spreadArray([], __read(effectActions.map(function (effectAction) { return [effectAction, currentState]; }))));
(_b = layoutEffectActionsRef.current).push.apply(_b, __spreadArray([], __read(layoutEffectActions.map(function (layoutEffectAction) { return [layoutEffectAction, currentState]; }))));
}

@@ -56,0 +57,0 @@ });

{
"name": "@xstate/react",
"version": "1.3.3",
"version": "1.3.4",
"description": "XState tools for React",

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

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

@@ -73,3 +73,3 @@ "main": "lib/index.js",

"@xstate/fsm": "*",
"jest": "^26.4.2",
"jest": "^26.6.3",
"jsdom": "^14.0.0",

@@ -84,6 +84,6 @@ "jsdom-global": "^3.0.2",

"rollup-plugin-typescript2": "^0.29.0",
"ts-jest": "^26.4.0",
"typescript": "^4.1.2",
"ts-jest": "^26.5.6",
"typescript": "^4.3.2",
"xstate": "*"
}
}

@@ -54,5 +54,5 @@ # @xstate/react

import { useMachine } from '@xstate/react';
import { Machine } from 'xstate';
import { createMachine } from 'xstate';
const toggleMachine = Machine({
const toggleMachine = createMachine({
id: 'toggle',

@@ -387,3 +387,3 @@ initial: 'inactive',

```js
const fetchMachine = Machine({
const fetchMachine = createMachine({
id: 'fetch',

@@ -390,0 +390,0 @@ initial: 'idle',

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