updated dist

main
Avraham Sakal 2 years ago
parent 8306fa67cf
commit 6b5ab3b37e

21
dist/index.d.ts vendored

@ -36,13 +36,22 @@ export interface Interpreter_T {
state: string; state: string;
context: any; context: any;
eventQueue: Array<Event_T>; eventQueue: Array<Event_T>;
isTransitioning: boolean;
subscriptions: Record<string, SubscriptionCallbackFunction_T>; subscriptions: Record<string, SubscriptionCallbackFunction_T>;
isTransitioning: boolean;
isPaused: boolean;
} }
export declare function interpret(machine: Machine_T, options: { /**
state?: string; * Description placeholder
context: any; *
}): Interpreter_T; * @export
* @param {Machine_T} machine
* @param {InitialContextFunction_T} initialContextFunction - in the form of a function rather than a direct value, so as to facilitate co-initialization of peer interpreters. Otherwise, the "parent" interpreter will start, but without a reference to a running child interpreter which it might expect to exist.
* @param {?string} [initialStateName]
* @returns {Interpreter_T}
*/
export declare function Interpreter(machine: Machine_T, initialContext: any, initialStateName?: string): Interpreter_T;
export declare function start(interpreter: Interpreter_T): void;
export declare function pause(interpreter: Interpreter_T): void;
/** Inject an Event into the Interpreter's "tick queue". /** Inject an Event into the Interpreter's "tick queue".
* *
* An event can be signify something "new" happening, such that its reactions should run on the next Tick; * An event can be signify something "new" happening, such that its reactions should run on the next Tick;
@ -56,7 +65,7 @@ export declare function interpret(machine: Machine_T, options: {
export declare function send(interpreter: Interpreter_T, event: Event_T): void; export declare function send(interpreter: Interpreter_T, event: Event_T): void;
export declare const enqueue: typeof send; export declare const enqueue: typeof send;
export type SubscriptionCallbackFunction_T = (self: Interpreter_T) => void; export type SubscriptionCallbackFunction_T = (self: Interpreter_T) => void;
export declare function subscribe(interpreter: Interpreter_T, callback: SubscriptionCallbackFunction_T): number; export declare function subscribe(interpreter: Interpreter_T, callback: SubscriptionCallbackFunction_T): string;
export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void; export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void;
export declare const Spawn: () => void; export declare const Spawn: () => void;
export declare const Unspawn: () => void; export declare const Unspawn: () => void;

2
dist/index.js vendored

@ -1,2 +1,2 @@
var l=function(...t){return{states:t}},g=function(t,...n){return{name:t,eventReactionCouplings:n}},y=function(t,...n){return{eventName:t,reactions:n}},E=function(t){return{type:"SideEffect",fn:t}},S=function(t){return{type:"Goto",targetStateName:t}},v=function(t){return{type:"ContextMutation",fn:t}};function d(t,n){let{state:e,context:i}=n;typeof e>"u"&&(e=t.states[0].name);let o={machine:t,state:e,context:i,eventQueue:[],isTransitioning:!1,subscriptions:{}};return c(o,["entry",null]),o}function T(t){return t.machine.states.find(n=>n.name===t.state)}function p(t,n){return t.eventReactionCouplings.filter(e=>e.eventName===n[0])}function c(t,n){if(t.eventQueue.push(n),t.isTransitioning===!1){for(t.isTransitioning=!0;t.eventQueue.length>0;)_(t);t.isTransitioning=!1,Object.values(t.subscriptions).forEach(e=>{e(t)})}}var C=c;function _(t){let n=t.eventQueue.shift();if(typeof n<"u"){let e=T(t),o=p(e,n).map(a=>a.reactions).flat(),{sideEffects:u,contextMutations:f,goto_:r}=x(o);u.forEach(a=>{a.fn(t.context,n,t)}),f.forEach(a=>{t.context=a.fn(t.context,n,t)}),r!==null&&(c(t,["exit",null]),t.state=r.targetStateName,c(t,["entry",null]))}}function x(t){let n=[],e=[],i=null;return t.forEach(o=>{o.type==="SideEffect"?n.push(o):o.type==="ContextMutation"?e.push(o):o.type==="Goto"&&(i=o)}),{sideEffects:n,contextMutations:e,goto_:i}}var s=0;function M(t,n){return s++,t.subscriptions[s.toString()]=n,s}function b(t,n){delete t.subscriptions[n.toString()]}var h=function(){},R=function(){};export{v as Context,S as Goto,l as Machine,y as On,E as SideEffect,h as Spawn,g as State,R as Unspawn,C as enqueue,d as interpret,c as send,M as subscribe,b as unsubscribe}; var g=function(...t){return{states:t}},y=function(t,...e){return{name:t,eventReactionCouplings:e}},E=function(t,...e){return{eventName:t,reactions:e}},d=function(t){return{type:"SideEffect",fn:t}},v=function(t){return{type:"Goto",targetStateName:t}},S=function(t){return{type:"ContextMutation",fn:t}};function C(t,e,n){typeof n>"u"&&(n=t.states[0].name);let i={machine:t,state:n,context:e,eventQueue:[],isTransitioning:!1,subscriptions:{},isPaused:!0};return a(i,["entry",null]),i}function b(t){t.isPaused=!1,u(t)}function M(t){t.isPaused=!0}function T(t){return t.machine.states.find(e=>e.name===t.state)}function _(t,e){return t.eventReactionCouplings.filter(n=>n.eventName===e[0])}function a(t,e){t.eventQueue.push(e),t.isTransitioning===!1&&u(t)}var h=a;function u(t){for(t.isTransitioning=!0;t.eventQueue.length>0&&t.isPaused===!1;)x(t);t.isTransitioning=!1,Object.values(t.subscriptions).forEach(e=>{e(t)})}function x(t){let e=t.eventQueue.shift();if(typeof e<"u"){let n=T(t),o=_(n,e).map(s=>s.reactions).flat(),{sideEffects:f,contextMutations:p,goto_:r}=l(o);f.forEach(s=>{s.fn(t.context,e,t)}),p.forEach(s=>{t.context=s.fn(t.context,e,t)}),r!==null&&(a(t,["exit",null]),t.state=r.targetStateName,a(t,["entry",null]))}}function l(t){let e=[],n=[],i=null;return t.forEach(o=>{o.type==="SideEffect"?e.push(o):o.type==="ContextMutation"?n.push(o):o.type==="Goto"&&(i=o)}),{sideEffects:e,contextMutations:n,goto_:i}}var c=0;function R(t,e){return c++,t.subscriptions[c.toString()]=e,c.toString()}function I(t,e){delete t.subscriptions[e.toString()]}var A=function(){},m=function(){};export{S as Context,v as Goto,C as Interpreter,g as Machine,E as On,d as SideEffect,A as Spawn,y as State,m as Unspawn,h as enqueue,M as pause,a as send,b as start,R as subscribe,I as unsubscribe};
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map

6
dist/index.js.map vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save