diff --git a/dist/index.d.ts b/dist/index.d.ts index de33095..877cca9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -36,13 +36,22 @@ export interface Interpreter_T { state: string; context: any; eventQueue: Array; - isTransitioning: boolean; subscriptions: Record; + isTransitioning: boolean; + isPaused: boolean; } -export declare function interpret(machine: Machine_T, options: { - state?: string; - context: any; -}): Interpreter_T; +/** + * Description placeholder + * + * @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". * * 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 const enqueue: typeof send; 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 const Spawn: () => void; export declare const Unspawn: () => void; diff --git a/dist/index.js b/dist/index.js index 75ae52c..148d0cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 diff --git a/dist/index.js.map b/dist/index.js.map index 049b441..c431a4e 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/index.ts"], - "sourcesContent": ["export type Event_T = [name:string, payload:any];\nexport interface Machine_T {\n states: Array\n}\nexport interface State_T {\n name: string;\n eventReactionCouplings: Array;\n}\nexport interface EventReactionCouplings_T {\n eventName: string;\n reactions: Array;\n};\nexport type Reaction_T = SideEffect_T | ContextMutation_T | Goto_T;\nexport interface SideEffect_T {\n type: 'SideEffect';\n fn: SideEffectFunction_T;\n};\nexport type SideEffectFunction_T = (ctx:any,e:Event_T,self:Interpreter_T)=>void;\nexport interface ContextMutation_T {\n type: 'ContextMutation';\n fn: ContextMutationFunction_T;\n};\nexport type ContextMutationFunction_T = (ctx:any,e:Event_T,self:Interpreter_T)=>any;\nexport interface Goto_T {\n type: 'Goto';\n targetStateName: string;\n};\n\nexport const Machine = function(...states:Array) : Machine_T { return {states}; };\nexport const State = function(name:string, ...eventReactionCouplings:Array) : State_T{ return {name, eventReactionCouplings}; };\nexport const On = function(eventName:string, ...reactions:Array) : EventReactionCouplings_T{ return {eventName, reactions}; };\nexport const SideEffect = function(fn:SideEffectFunction_T) : SideEffect_T{ return {type:'SideEffect', fn}; };\nexport const Goto = function(targetStateName:string) : Goto_T { return {type:'Goto', targetStateName} };\nexport const Context = function(fn:ContextMutationFunction_T) : ContextMutation_T { return {type:'ContextMutation', fn} };\n\n\n\n\n\nexport interface Interpreter_T {\n machine: Machine_T;\n state: string;\n context: any;\n eventQueue:Array;\n isTransitioning: boolean;\n subscriptions: Record\n}\nexport function interpret(machine:Machine_T, options:{state?:string, context:any}) : Interpreter_T{\n let {state, context} = options;\n if(typeof state === 'undefined'){ state = machine.states[0].name; }\n const interpreter = {machine, state, context, eventQueue:[], isTransitioning:false, subscriptions: {}}\n send(interpreter, ['entry', null] );\n return interpreter;\n}\n\n/** Helper function for `send()`\n */\nfunction getState(interpreter : Interpreter_T) : State_T{\n return interpreter.machine.states.find((state)=>state.name===interpreter.state) as unknown as State_T;\n}\n/** Helper function for `send()`\n */\nfunction getMatchingEventReactionCouplings(state : State_T, event:Event_T) : Array{\n return state.eventReactionCouplings.filter((eventReactionCoupling)=>eventReactionCoupling.eventName===event[0]);\n}\n/** Inject an Event into the Interpreter's \"tick queue\".\n * \n * An event can be signify something \"new\" happening, such that its reactions should run on the next Tick;\n * or it can signify a milestone \"within\" the current Tick, such that a Tick can be thought of as having \n * \"sub-Ticks\".\n * \n * This distinction is significant for proper ordering of reaction execution, and also for determining\n * whether to run a reaction at all. If an Event is received, and is specified to be applied on a past \n * Tick, it is discarded.\n */\nexport function send(interpreter : Interpreter_T, event:Event_T){\n interpreter.eventQueue.push(event);\n if(interpreter.isTransitioning === false){\n interpreter.isTransitioning = true;\n while(interpreter.eventQueue.length > 0){\n processNextEvent(interpreter);\n }\n interpreter.isTransitioning = false;\n // only run subscriptions here, once the machine's state has settled:\n Object.values(interpreter.subscriptions).forEach((subscriptionCallbackFunction)=>{ subscriptionCallbackFunction(interpreter); });\n }\n}\nexport const enqueue = send;\nfunction processNextEvent(interpreter:Interpreter_T){\n const nextEvent = interpreter.eventQueue.shift();\n if(typeof nextEvent !== 'undefined'){\n const state = getState(interpreter);\n const eventReactionCouplings = getMatchingEventReactionCouplings(state, nextEvent);\n const reactions = eventReactionCouplings\n .map((eventReactionCoupling)=>eventReactionCoupling.reactions)\n .flat();\n const {sideEffects, contextMutations, goto_} = categorizeReactions(reactions);\n // can process sideEffects in parallel:\n sideEffects.forEach((sideEffect)=>{\n sideEffect.fn(interpreter.context, nextEvent, interpreter);\n });\n // must process contextMutations in-series:\n contextMutations.forEach((contextMutation)=>{\n interpreter.context = contextMutation.fn(interpreter.context, nextEvent, interpreter);\n });\n // processing of `goto` must be last:\n if(goto_ !== null){\n send(interpreter, ['exit', null]);\n interpreter.state = goto_.targetStateName;\n send(interpreter, ['entry', null]);\n }\n }\n}\nfunction categorizeReactions(reactions:Array) : {sideEffects:Array, contextMutations:Array, goto_:Goto_T|null}{\n let \n sideEffects:Array = [], \n contextMutations:Array = [], \n goto_:Goto_T|null = null;\n reactions.forEach((reaction)=>{\n if(reaction.type === 'SideEffect'){\n sideEffects.push(reaction);\n }\n else if(reaction.type === 'ContextMutation'){\n contextMutations.push(reaction);\n }\n else if(reaction.type === 'Goto'){\n goto_ = reaction;\n }\n });\n return {sideEffects, contextMutations, goto_};\n}\n\nexport type SubscriptionCallbackFunction_T = (self:Interpreter_T)=>void;\nlet subscriptionId : number = 0;\nexport function subscribe(interpreter:Interpreter_T, callback:SubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptions[subscriptionId.toString()] = callback;\n return subscriptionId;\n}\nexport function unsubscribe(interpreter:Interpreter_T, subscriptionId:string){\n delete interpreter.subscriptions[subscriptionId.toString()];\n}\n\nexport const Spawn = function(){};\nexport const Unspawn = function(){};\n\n/*\nexport function useMachine(machine, options){\n return useMemo(()=>interpret(AppMachine, {context:{}}),[]);\n}\n*/"], - "mappings": "AA4BO,IAAMA,EAAU,YAAYC,EAAmC,CAAE,MAAO,CAAC,OAAAA,CAAM,CAAG,EAC5EC,EAAQ,SAASC,KAAgBC,EAAiE,CAAE,MAAO,CAAC,KAAAD,EAAM,uBAAAC,CAAsB,CAAG,EAC3IC,EAAK,SAASC,KAAqBC,EAAuD,CAAE,MAAO,CAAC,UAAAD,EAAW,UAAAC,CAAS,CAAG,EAC3HC,EAAa,SAASC,EAAuC,CAAE,MAAO,CAAC,KAAK,aAAc,GAAAA,CAAE,CAAG,EAC/FC,EAAO,SAASC,EAAiC,CAAE,MAAO,CAAC,KAAK,OAAQ,gBAAAA,CAAe,CAAE,EACzFC,EAAU,SAASH,EAAkD,CAAE,MAAO,CAAC,KAAK,kBAAmB,GAAAA,CAAE,CAAE,EAcjH,SAASI,EAAUC,EAAmBC,EAAqD,CAChG,GAAI,CAAC,MAAAC,EAAO,QAAAC,CAAO,EAAIF,EACpB,OAAOC,EAAU,MAAcA,EAAQF,EAAQ,OAAO,CAAC,EAAE,MAC5D,IAAMI,EAAc,CAAC,QAAAJ,EAAS,MAAAE,EAAO,QAAAC,EAAS,WAAW,CAAC,EAAG,gBAAgB,GAAO,cAAe,CAAC,CAAC,EACrG,OAAAE,EAAKD,EAAa,CAAC,QAAS,IAAI,CAAE,EAC3BA,CACT,CAIA,SAASE,EAASF,EAAsC,CACtD,OAAOA,EAAY,QAAQ,OAAO,KAAMF,GAAQA,EAAM,OAAOE,EAAY,KAAK,CAChF,CAGA,SAASG,EAAkCL,EAAiBM,EAAgD,CAC1G,OAAON,EAAM,uBAAuB,OAAQO,GAAwBA,EAAsB,YAAYD,EAAM,CAAC,CAAC,CAChH,CAWO,SAASH,EAAKD,EAA6BI,EAAc,CAE9D,GADAJ,EAAY,WAAW,KAAKI,CAAK,EAC9B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A2BmB,EAAwC,CAC3F,OAAAF,IACAjB,EAAY,cAAciB,EAAe,SAAS,CAAC,EAAIE,EAChDF,CACT,CACO,SAASG,EAAYpB,EAA2BiB,EAAsB,CAC3E,OAAOjB,EAAY,cAAciB,EAAe,SAAS,CAAC,CAC5D,CAEO,IAAMI,EAAQ,UAAU,CAAC,EACnBC,EAAU,UAAU,CAAC", - "names": ["Machine", "states", "State", "name", "eventReactionCouplings", "On", "eventName", "reactions", "SideEffect", "fn", "Goto", "targetStateName", "Context", "interpret", "machine", "options", "state", "context", "interpreter", "send", "getState", "getMatchingEventReactionCouplings", "event", "eventReactionCoupling", "processNextEvent", "subscriptionCallbackFunction", "enqueue", "nextEvent", "sideEffects", "contextMutations", "goto_", "categorizeReactions", "sideEffect", "contextMutation", "reaction", "subscriptionId", "subscribe", "callback", "unsubscribe", "Spawn", "Unspawn"] + "sourcesContent": ["export type Event_T = [name:string, payload:any];\nexport interface Machine_T {\n states: Array\n}\nexport interface State_T {\n name: string;\n eventReactionCouplings: Array;\n}\nexport interface EventReactionCouplings_T {\n eventName: string;\n reactions: Array;\n};\nexport type Reaction_T = SideEffect_T | ContextMutation_T | Goto_T;\nexport interface SideEffect_T {\n type: 'SideEffect';\n fn: SideEffectFunction_T;\n};\nexport type SideEffectFunction_T = (ctx:any,e:Event_T,self:Interpreter_T)=>void;\nexport interface ContextMutation_T {\n type: 'ContextMutation';\n fn: ContextMutationFunction_T;\n};\nexport type ContextMutationFunction_T = (ctx:any,e:Event_T,self:Interpreter_T)=>any;\nexport interface Goto_T {\n type: 'Goto';\n targetStateName: string;\n};\n\nexport const Machine = function(...states:Array) : Machine_T { return {states}; };\nexport const State = function(name:string, ...eventReactionCouplings:Array) : State_T{ return {name, eventReactionCouplings}; };\nexport const On = function(eventName:string, ...reactions:Array) : EventReactionCouplings_T{ return {eventName, reactions}; };\nexport const SideEffect = function(fn:SideEffectFunction_T) : SideEffect_T{ return {type:'SideEffect', fn}; };\nexport const Goto = function(targetStateName:string) : Goto_T { return {type:'Goto', targetStateName} };\nexport const Context = function(fn:ContextMutationFunction_T) : ContextMutation_T { return {type:'ContextMutation', fn} };\n\n\n\n\n\nexport interface Interpreter_T {\n machine: Machine_T;\n state: string;\n context: any;\n eventQueue:Array;\n subscriptions: Record;\n isTransitioning: boolean;\n isPaused: boolean;\n}\n\n/**\n * Description placeholder\n *\n * @export\n * @param {Machine_T} machine\n * @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.\n * @param {?string} [initialStateName]\n * @returns {Interpreter_T}\n */\nexport function Interpreter(machine:Machine_T, initialContext:any, initialStateName?:string) : Interpreter_T{\n if(typeof initialStateName === 'undefined'){ initialStateName = machine.states[0].name; }\n const interpreter = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, subscriptions: {}, isPaused: true}\n send(interpreter, ['entry', null] );\n return interpreter;\n}\nexport function start(interpreter:Interpreter_T){\n interpreter.isPaused = false;\n processEvents(interpreter);\n}\nexport function pause(interpreter:Interpreter_T){\n interpreter.isPaused = true;\n}\n\n/** Helper function for `send()`\n */\nfunction getState(interpreter : Interpreter_T) : State_T{\n return interpreter.machine.states.find((state)=>state.name===interpreter.state) as unknown as State_T;\n}\n/** Helper function for `send()`\n */\nfunction getMatchingEventReactionCouplings(state : State_T, event:Event_T) : Array{\n return state.eventReactionCouplings.filter((eventReactionCoupling)=>eventReactionCoupling.eventName===event[0]);\n}\n/** Inject an Event into the Interpreter's \"tick queue\".\n * \n * An event can be signify something \"new\" happening, such that its reactions should run on the next Tick;\n * or it can signify a milestone \"within\" the current Tick, such that a Tick can be thought of as having \n * \"sub-Ticks\".\n * \n * This distinction is significant for proper ordering of reaction execution, and also for determining\n * whether to run a reaction at all. If an Event is received, and is specified to be applied on a past \n * Tick, it is discarded.\n */\nexport function send(interpreter : Interpreter_T, event:Event_T){\n interpreter.eventQueue.push(event);\n if(interpreter.isTransitioning === false){\n processEvents(interpreter);\n }\n}\nexport const enqueue = send;\nfunction processEvents(interpreter:Interpreter_T){\n interpreter.isTransitioning = true;\n while(interpreter.eventQueue.length > 0 && interpreter.isPaused===false){\n processNextEvent(interpreter);\n }\n interpreter.isTransitioning = false;\n // only run subscriptions here, once the machine's state has settled:\n Object.values(interpreter.subscriptions).forEach((subscriptionCallbackFunction)=>{ subscriptionCallbackFunction(interpreter); });\n}\nfunction processNextEvent(interpreter:Interpreter_T){\n const nextEvent = interpreter.eventQueue.shift();\n if(typeof nextEvent !== 'undefined'){\n const state = getState(interpreter);\n const eventReactionCouplings = getMatchingEventReactionCouplings(state, nextEvent);\n const reactions = eventReactionCouplings\n .map((eventReactionCoupling)=>eventReactionCoupling.reactions)\n .flat();\n const {sideEffects, contextMutations, goto_} = categorizeReactions(reactions);\n // can process sideEffects in parallel:\n sideEffects.forEach((sideEffect)=>{\n sideEffect.fn(interpreter.context, nextEvent, interpreter);\n });\n // must process contextMutations in-series:\n contextMutations.forEach((contextMutation)=>{\n interpreter.context = contextMutation.fn(interpreter.context, nextEvent, interpreter);\n });\n // processing of `goto` must be last:\n if(goto_ !== null){\n send(interpreter, ['exit', null]);\n interpreter.state = goto_.targetStateName;\n send(interpreter, ['entry', null]);\n }\n }\n}\nfunction categorizeReactions(reactions:Array) : {sideEffects:Array, contextMutations:Array, goto_:Goto_T|null}{\n let \n sideEffects:Array = [], \n contextMutations:Array = [], \n goto_:Goto_T|null = null;\n reactions.forEach((reaction)=>{\n if(reaction.type === 'SideEffect'){\n sideEffects.push(reaction);\n }\n else if(reaction.type === 'ContextMutation'){\n contextMutations.push(reaction);\n }\n else if(reaction.type === 'Goto'){\n goto_ = reaction;\n }\n });\n return {sideEffects, contextMutations, goto_};\n}\n\nexport type SubscriptionCallbackFunction_T = (self:Interpreter_T)=>void;\nlet subscriptionId : number = 0;\nexport function subscribe(interpreter:Interpreter_T, callback:SubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptions[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport function unsubscribe(interpreter:Interpreter_T, subscriptionId:string){\n delete interpreter.subscriptions[subscriptionId.toString()];\n}\n\nexport const Spawn = function(){};\nexport const Unspawn = function(){};\n\n/*\nexport function useMachine(machine, options){\n return useMemo(()=>interpret(AppMachine, {context:{}}),[]);\n}\n*/"], + "mappings": "AA4BO,IAAMA,EAAU,YAAYC,EAAmC,CAAE,MAAO,CAAC,OAAAA,CAAM,CAAG,EAC5EC,EAAQ,SAASC,KAAgBC,EAAiE,CAAE,MAAO,CAAC,KAAAD,EAAM,uBAAAC,CAAsB,CAAG,EAC3IC,EAAK,SAASC,KAAqBC,EAAuD,CAAE,MAAO,CAAC,UAAAD,EAAW,UAAAC,CAAS,CAAG,EAC3HC,EAAa,SAASC,EAAuC,CAAE,MAAO,CAAC,KAAK,aAAc,GAAAA,CAAE,CAAG,EAC/FC,EAAO,SAASC,EAAiC,CAAE,MAAO,CAAC,KAAK,OAAQ,gBAAAA,CAAe,CAAE,EACzFC,EAAU,SAASH,EAAkD,CAAE,MAAO,CAAC,KAAK,kBAAmB,GAAAA,CAAE,CAAE,EAyBjH,SAASI,EAAYC,EAAmBC,EAAoBC,EAAyC,CACvG,OAAOA,EAAqB,MAAcA,EAAmBF,EAAQ,OAAO,CAAC,EAAE,MAClF,IAAMG,EAAc,CAAC,QAAAH,EAAS,MAAOE,EAAkB,QAAQD,EAAgB,WAAW,CAAC,EAAG,gBAAgB,GAAO,cAAe,CAAC,EAAG,SAAU,EAAI,EACtJ,OAAAG,EAAKD,EAAa,CAAC,QAAS,IAAI,CAAE,EAC3BA,CACT,CACO,SAASE,EAAMF,EAA0B,CAC9CA,EAAY,SAAW,GACvBG,EAAcH,CAAW,CAC3B,CACO,SAASI,EAAMJ,EAA0B,CAC9CA,EAAY,SAAW,EACzB,CAIA,SAASK,EAASL,EAAsC,CACtD,OAAOA,EAAY,QAAQ,OAAO,KAAMM,GAAQA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EAC7CC,EAAoB,KACtB,OAAA1B,EAAU,QAAS8B,GAAW,CACzBA,EAAS,OAAS,aACnBN,EAAY,KAAKM,CAAQ,EAEnBA,EAAS,OAAS,kBACxBL,EAAiB,KAAKK,CAAQ,EAExBA,EAAS,OAAS,SACxBJ,EAAQI,EAEZ,CAAC,EACM,CAAC,YAAAN,EAAa,iBAAAC,EAAkB,MAAAC,CAAK,CAC9C,CAGA,IAAIK,EAA0B,EACvB,SAASC,EAAUtB,EAA2BuB,EAAwC,CAC3F,OAAAF,IACArB,EAAY,cAAcqB,EAAe,SAAS,CAAC,EAAIE,EAChDF,EAAe,SAAS,CACjC,CACO,SAASG,EAAYxB,EAA2BqB,EAAsB,CAC3E,OAAOrB,EAAY,cAAcqB,EAAe,SAAS,CAAC,CAC5D,CAEO,IAAMI,EAAQ,UAAU,CAAC,EACnBC,EAAU,UAAU,CAAC", + "names": ["Machine", "states", "State", "name", "eventReactionCouplings", "On", "eventName", "reactions", "SideEffect", "fn", "Goto", "targetStateName", "Context", "Interpreter", "machine", "initialContext", "initialStateName", "interpreter", "send", "start", "processEvents", "pause", "getState", "state", "getMatchingEventReactionCouplings", "event", "eventReactionCoupling", "enqueue", "processNextEvent", "subscriptionCallbackFunction", "nextEvent", "sideEffects", "contextMutations", "goto_", "categorizeReactions", "sideEffect", "contextMutation", "reaction", "subscriptionId", "subscribe", "callback", "unsubscribe", "Spawn", "Unspawn"] }