diff --git a/dist/index.d.ts b/dist/index.d.ts index b55ad64..c683dec 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -10,7 +10,7 @@ export interface EventReactionCouplings_T { eventName: string; reactions: Array>; } -export type Reaction_T = SideEffect_T | ContextMutation_T | Peering_T | Goto_T; +export type Reaction_T = SideEffect_T | ContextMutation_T | Peer_T | Goto_T; export interface SideEffect_T { type: 'SideEffect'; fn: SideEffectFunction_T; @@ -21,12 +21,12 @@ export interface ContextMutation_T { fn: ContextMutationFunction_T; } export type ContextMutationFunction_T = (ctx: C, e: Event_T, self: Interpreter_T) => C; -export interface Peering_T { - type: 'Peering'; +export interface Peer_T { + type: 'SetPeer' | 'SetPeers' | 'AddPeers'; name: string; peerCreationFunction: PeerCreationFunction_T; } -export type PeerCreationFunction_T = (ctx: C, e: Event_T, self: Interpreter_T) => Interpreter_T; +export type PeerCreationFunction_T = (ctx: C, e: Event_T, self: Interpreter_T) => Interpreter_T | Array>; export interface Goto_T { type: 'Goto'; targetStateName: string; @@ -37,12 +37,14 @@ export declare const On: (eventName: string, ...reactions: Reaction_T[]) = export declare const SideEffect: (fn: SideEffectFunction_T) => SideEffect_T; export declare const Goto: (targetStateName: string) => Goto_T; export declare const Context: (fn: ContextMutationFunction_T) => ContextMutation_T; -export declare const Peer: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peering_T; +export declare const Peer: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; +export declare const Peers: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; +export declare const AddPeers: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; export interface Interpreter_T { machine: Machine_T; state: string; context: C; - peers: Record>; + peers: Record | Array>>; peerSubscriptionIds: Map, string>; eventQueue: Array; subscriptionsToEvents: Record>; @@ -84,4 +86,6 @@ export declare const subscribeToSettledState: typeof subscribe; export declare function subscribeToState(interpreter: Interpreter_T, callback: StateSubscriptionCallbackFunction_T): string; export declare function subscribeToEvents(interpreter: Interpreter_T, callback: StateSubscriptionCallbackFunction_T): string; export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void; -export declare function addPeer(self: Interpreter_T, name: string, peer: Interpreter_T): void; +export declare function setPeer(self: Interpreter_T, name: string, peer: Interpreter_T): void; +export declare function setPeers(self: Interpreter_T, name: string, peers: Array>): void; +export declare function addPeers(self: Interpreter_T, name: string, peers: Array>): void; diff --git a/dist/index.js b/dist/index.js index 2e5a040..06439d6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -var v=function(...t){return{states:t}},y=function(t,...e){return{name:t,eventReactionCouplings:e}},P=function(t,...e){return{eventName:t,reactions:e}},I=function(t){return{type:"SideEffect",fn:t}},M=function(t){return{type:"Goto",targetStateName:t}},h=function(t){return{type:"ContextMutation",fn:t}},F=function(t,e){return{type:"Peering",name:t,peerCreationFunction:e}};function R(t,e,n){typeof n>"u"&&(n=t.states[0].name);let o={machine:t,state:n,context:e,eventQueue:[],isTransitioning:!1,peers:{},peerSubscriptionIds:new Map,subscriptionsToEvents:{},subscriptionsToState:{},subscriptionsToSettledState:{},isPaused:!0};return o.start=()=>(f(o),o),c(o,["entry",null]),o}function f(t){t.isPaused===!0&&(t.isPaused=!1,C(t))}function k(t){t.isPaused===!1&&(t.isPaused=!0)}function l(t){return t.machine.states.find(e=>e.name===t.state)}function S(t,e){return t.eventReactionCouplings.filter(n=>n.eventName===e[0])}function c(t,e){t.eventQueue.push(e),t.isTransitioning===!1&&C(t)}var A=c;function C(t){for(t.isTransitioning=!0;t.eventQueue.length>0&&t.isPaused===!1;)g(t);t.isTransitioning=!1,Object.values(t.subscriptionsToSettledState).forEach(e=>{e(t)})}function g(t){let e=t.eventQueue.shift();if(typeof e<"u"){let n=l(t),a=S(n,e).map(i=>i.reactions).flat(),{sideEffects:r,contextMutations:T,peerings:p,goto_:u}=x(a),_=t.context;T.forEach(i=>{t.context=i.fn(t.context,e,t)}),u!==null&&(c(t,["exit",null]),t.state=u.targetStateName,Object.values(t.subscriptionsToState).forEach(i=>{i(e,t)}),c(t,["entry",null])),p.forEach(i=>{E(t,i.name,i.peerCreationFunction(t.context,e,t))}),Object.values(t.subscriptionsToEvents).forEach(i=>{i(e,t)}),r.forEach(i=>{i.fn(t.context,e,t,_)})}}function x(t){let e=[],n=[],o=[],a=null;return t.forEach(r=>{r.type==="SideEffect"?e.push(r):r.type==="ContextMutation"?n.push(r):r.type==="Peering"?o.push(r):r.type==="Goto"&&(a=r)}),{sideEffects:e,contextMutations:n,peerings:o,goto_:a}}var s=0;function d(t,e){return s++,t.subscriptionsToSettledState[s.toString()]=e,s.toString()}var m=d;function G(t,e){return s++,t.subscriptionsToState[s.toString()]=e,s.toString()}function b(t,e){return s++,t.subscriptionsToEvents[s.toString()]=e,s.toString()}function w(t,e){delete t.subscriptionsToSettledState[e.toString()],delete t.subscriptionsToState[e.toString()],delete t.subscriptionsToEvents[e.toString()]}function E(t,e,n){t.peers[e]=n,b(n,(o,a)=>{t.isTransitioning===!1&&c(t,[e+"."+o[0],o[1]])})}export{h as Context,M as Goto,R as Interpreter,v as Machine,P as On,F as Peer,I as SideEffect,y as State,E as addPeer,A as enqueue,k as pause,c as send,f as start,d as subscribe,b as subscribeToEvents,m as subscribeToSettledState,G as subscribeToState,w as unsubscribe}; +var v=function(...t){return{states:t}},h=function(t,...e){return{name:t,eventReactionCouplings:e}},A=function(t,...e){return{eventName:t,reactions:e}},F=function(t){return{type:"SideEffect",fn:t}},M=function(t){return{type:"Goto",targetStateName:t}},k=function(t){return{type:"ContextMutation",fn:t}},R=function(t,e){return{type:"SetPeer",name:t,peerCreationFunction:e}},w=function(t,e){return{type:"SetPeers",name:t,peerCreationFunction:e}},G=function(t,e){return{type:"AddPeers",name:t,peerCreationFunction:e}};function O(t,e,n){typeof n>"u"&&(n=t.states[0].name);let r={machine:t,state:n,context:e,eventQueue:[],isTransitioning:!1,peers:{},peerSubscriptionIds:new Map,subscriptionsToEvents:{},subscriptionsToState:{},subscriptionsToSettledState:{},isPaused:!0};return r.start=()=>(x(r),r),c(r,["entry",null]),r}function x(t){t.isPaused===!0&&(t.isPaused=!1,T(t))}function Q(t){t.isPaused===!1&&(t.isPaused=!0)}function d(t){return t.machine.states.find(e=>e.name===t.state)}function l(t,e){return t.eventReactionCouplings.filter(n=>n.eventName===e[0])}function c(t,e){t.eventQueue.push(e),t.isTransitioning===!1&&T(t)}var m=c;function T(t){for(t.isTransitioning=!0;t.eventQueue.length>0&&t.isPaused===!1;)P(t);t.isTransitioning=!1,Object.values(t.subscriptionsToSettledState).forEach(e=>{e(t)})}function P(t){let e=t.eventQueue.shift();if(typeof e<"u"){let n=d(t),i=l(n,e).map(o=>o.reactions).flat(),{sideEffects:s,contextMutations:u,peerings:f,goto_:p}=b(i),S=t.context;u.forEach(o=>{t.context=o.fn(t.context,e,t)}),p!==null&&(c(t,["exit",null]),t.state=p.targetStateName,Object.values(t.subscriptionsToState).forEach(o=>{o(e,t)}),c(t,["entry",null])),f.forEach(o=>{o.type==="SetPeer"?y(t,o.name,o.peerCreationFunction(t.context,e,t)):o.type==="SetPeers"?E(t,o.name,o.peerCreationFunction(t.context,e,t)):o.type==="AddPeers"&&I(t,o.name,o.peerCreationFunction(t.context,e,t))}),Object.values(t.subscriptionsToEvents).forEach(o=>{o(e,t)}),s.forEach(o=>{o.fn(t.context,e,t,S)})}}function b(t){let e=[],n=[],r=[],i=null;return t.forEach(s=>{s.type==="SideEffect"?e.push(s):s.type==="ContextMutation"?n.push(s):s.type==="SetPeer"?r.push(s):s.type==="Goto"&&(i=s)}),{sideEffects:e,contextMutations:n,peerings:r,goto_:i}}var a=0;function g(t,e){return a++,t.subscriptionsToSettledState[a.toString()]=e,a.toString()}var j=g;function N(t,e){return a++,t.subscriptionsToState[a.toString()]=e,a.toString()}function C(t,e){return a++,t.subscriptionsToEvents[a.toString()]=e,a.toString()}function _(t,e){delete t.subscriptionsToSettledState[e.toString()],delete t.subscriptionsToState[e.toString()],delete t.subscriptionsToEvents[e.toString()]}function y(t,e,n){t.peers.hasOwnProperty(e)&&_(t,t.peerSubscriptionIds.get(t.peers[e])),t.peers[e]=n;let r=C(n,(i,s)=>{t.isTransitioning===!1&&c(t,[e+"."+i[0],i[1]])});t.peerSubscriptionIds.set(n,r)}function E(t,e,n){t.peers.hasOwnProperty(e)&&t.peers[e].forEach(r=>{_(t,t.peerSubscriptionIds.get(r))}),t.peers[e]=n,n.forEach(r=>{let i=C(r,(s,u)=>{t.isTransitioning===!1&&c(t,[e+"."+s[0],s[1]])});t.peerSubscriptionIds.set(r,i)})}function I(t,e,n){t.peers.hasOwnProperty(e)||(t.peers[e]=[]),t.peers[e].concat(n),n.forEach(r=>{let i=C(r,(s,u)=>{t.isTransitioning===!1&&c(t,[e+"."+s[0],s[1]])});t.peerSubscriptionIds.set(r,i)})}export{G as AddPeers,k as Context,M as Goto,O as Interpreter,v as Machine,A as On,R as Peer,w as Peers,F as SideEffect,h as State,I as addPeers,m as enqueue,Q as pause,c as send,y as setPeer,E as setPeers,x as start,g as subscribe,C as subscribeToEvents,j as subscribeToSettledState,N as subscribeToState,_ as unsubscribe}; //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index 672979d..b5cce40 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 | Peering_T | Goto_T;\nexport interface SideEffect_T {\n type: 'SideEffect';\n fn: SideEffectFunction_T;\n};\nexport type SideEffectFunction_T = (ctx:C,e:Event_T,self:Interpreter_T,originalContext:C)=>void;\nexport interface ContextMutation_T {\n type: 'ContextMutation';\n fn: ContextMutationFunction_T;\n};\nexport type ContextMutationFunction_T = (ctx:C,e:Event_T,self:Interpreter_T)=>C;\nexport interface Peering_T {\n type: 'Peering';\n name: string;\n peerCreationFunction: PeerCreationFunction_T\n};\nexport type PeerCreationFunction_T = (ctx:C,e:Event_T,self:Interpreter_T) => Interpreter_T;\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} };\nexport const Peer = function(name:string, peerCreationFunction:PeerCreationFunction_T) : Peering_T{ return {type:'Peering', name, peerCreationFunction}; }\n\n\nexport interface Interpreter_T {\n machine: Machine_T;\n state: string;\n context: C;\n peers: Record>;\n peerSubscriptionIds: Map,string>;\n eventQueue:Array;\n subscriptionsToEvents: Record>; // called upon every event\n subscriptionsToState: Record>; // every time state changes, even if it's transient\n subscriptionsToSettledState: Record>; // only called when tick settles\n isTransitioning: boolean;\n isPaused: boolean;\n start: ()=>Interpreter_T;\n}\n\n/**\n * Description placeholder\n *\n * @export\n * @param {Machine_T} machine\n * @param {any} initialContext\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 //@ts-expect-error\n const interpreter : Interpreter_T = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, peers:{}, peerSubscriptionIds:new Map(), subscriptionsToEvents: {}, subscriptionsToState: {}, subscriptionsToSettledState: {}, isPaused: true};\n interpreter.start = ()=>{ start(interpreter); return interpreter; }\n send(interpreter, ['entry', null] );\n return interpreter;\n}\nexport function start(interpreter:Interpreter_T){\n if(interpreter.isPaused === true){\n interpreter.isPaused = false;\n processEvents(interpreter);\n }\n}\nexport function pause(interpreter:Interpreter_T){\n if(interpreter.isPaused === false){\n interpreter.isPaused = true;\n }\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.subscriptionsToSettledState).forEach((callbackFunction)=>{ callbackFunction(interpreter); });\n}\nfunction processNextEvent(interpreter:Interpreter_T){\n const event = interpreter.eventQueue.shift();\n if(typeof event !== 'undefined'){\n const state = getState(interpreter);\n const eventReactionCouplings = getMatchingEventReactionCouplings(state, event);\n const reactions = eventReactionCouplings\n .map((eventReactionCoupling)=>eventReactionCoupling.reactions)\n .flat();\n const {sideEffects, contextMutations, peerings, goto_} = categorizeReactions(reactions);\n // save the current context, before it's mutated, so as to pass it to sideEffects below:\n const originalContext = interpreter.context;\n // must process contextMutations in-series:\n contextMutations.forEach((contextMutation)=>{\n interpreter.context = contextMutation.fn(interpreter.context, event, interpreter);\n });\n // processing of `goto` must be last:\n if(goto_ !== null){\n send(interpreter, ['exit', null]);\n interpreter.state = goto_.targetStateName;\n // run subscription-to-state callbacks (can be in parallel), since state just changed, possibly transiently (depends on whether the loop in `processEvents()` runs again):\n Object.values(interpreter.subscriptionsToState).forEach((callbackFunction)=>{ callbackFunction(event, interpreter); });\n send(interpreter, ['entry', null]);\n }\n // now that \"internal\" stuff has been run, we can run \"external\" stuff:\n // process peerings (possibly in parallel):\n peerings.forEach((peering)=>{ addPeer(interpreter, peering.name, peering.peerCreationFunction(interpreter.context, event, interpreter)); });\n // run subscription-to-events callbacks (can be in parallel), since an event just happened:\n Object.values(interpreter.subscriptionsToEvents).forEach((callbackFunction)=>{ callbackFunction(event, interpreter); });\n // can process sideEffects in parallel (though we currently don't due to the overhead of doing so in Node.js):\n // they're processed *after* the context changes, since that's what most sideEffects would be interested in; but nevertheless the original context is passed in case this sideEffect needs it:\n sideEffects.forEach((sideEffect)=>{\n sideEffect.fn(interpreter.context, event, interpreter, originalContext);\n });\n }\n}\nfunction categorizeReactions(reactions:Array>) : {sideEffects:Array>, contextMutations:Array>, peerings:Array>, goto_:Goto_T|null}{\n let \n sideEffects:Array> = [], \n contextMutations:Array> = [], \n peerings: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 === 'Peering'){\n peerings.push(reaction);\n }\n else if(reaction.type === 'Goto'){\n goto_ = reaction;\n }\n });\n return {sideEffects, contextMutations, peerings, goto_};\n}\n\nexport type EventsSubscriptionCallbackFunction_T = (e:Event_T, self:Interpreter_T)=>void;\nexport type StateSubscriptionCallbackFunction_T = (e:Event_T, self:Interpreter_T)=>void;\nexport type SettledStateSubscriptionCallbackFunction_T = (self:Interpreter_T)=>void; // we don't pass an event, because these only run once state settles, so a whole chain of events could have been responsible for that; it's unlikely a subscriber is interested only in the final one\n// TODO: add subscribeToContext and subscribeToSettledContext functions, to get only changes to context, regardless of events happening or state changing\nlet subscriptionId : number = 0;\nexport function subscribe(interpreter:Interpreter_T, callback:SettledStateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToSettledState[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport const subscribeToSettledState = subscribe;\nexport function subscribeToState(interpreter:Interpreter_T, callback:StateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToState[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport function subscribeToEvents(interpreter:Interpreter_T, callback:StateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToEvents[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport function unsubscribe(interpreter:Interpreter_T, subscriptionId:string){\n delete interpreter.subscriptionsToSettledState[subscriptionId.toString()];\n delete interpreter.subscriptionsToState[subscriptionId.toString()];\n delete interpreter.subscriptionsToEvents[subscriptionId.toString()];\n}\n\nexport function addPeer(self:Interpreter_T, name:string, peer:Interpreter_T){\n self.peers[name] = peer;\n subscribeToEvents(peer, (e, peer)=>{\n // this `if` prevents infinite loops due to mutually-subscribed peers (cyclical dependencies):\n if(self.isTransitioning === false){\n send(self, [name+'.'+e[0], e[1]]);\n }\n });\n}\n\n/*\nexport function useMachine(machine, options){\n return useMemo(()=>interpret(AppMachine, {context:{}}),[]);\n}\n*/"], - "mappings": "AAkCO,IAAMA,EAAU,YAAeC,EAAyC,CAAE,MAAO,CAAC,OAAAA,CAAM,CAAG,EACrFC,EAAQ,SAAYC,KAAgBC,EAAuE,CAAE,MAAO,CAAC,KAAAD,EAAM,uBAAAC,CAAsB,CAAG,EACpJC,EAAK,SAAYC,KAAqBC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BG,EAAM,CAACC,EAAGD,IAAO,CAE9BD,EAAK,kBAAoB,IAC1B7B,EAAK6B,EAAM,CAAC/C,EAAK,IAAIiD,EAAE,CAAC,EAAGA,EAAE,CAAC,CAAC,CAAC,CAEpC,CAAC,CACH", - "names": ["Machine", "states", "State", "name", "eventReactionCouplings", "On", "eventName", "reactions", "SideEffect", "fn", "Goto", "targetStateName", "Context", "Peer", "peerCreationFunction", "Interpreter", "machine", "initialContext", "initialStateName", "interpreter", "start", "send", "processEvents", "pause", "getState", "state", "getMatchingEventReactionCouplings", "event", "eventReactionCoupling", "enqueue", "processNextEvent", "callbackFunction", "sideEffects", "contextMutations", "peerings", "goto_", "categorizeReactions", "originalContext", "contextMutation", "peering", "addPeer", "sideEffect", "reaction", "subscriptionId", "subscribe", "callback", "subscribeToSettledState", "subscribeToState", "subscribeToEvents", "unsubscribe", "self", "peer", "e"] + "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 | Peer_T | Goto_T;\nexport interface SideEffect_T {\n type: 'SideEffect';\n fn: SideEffectFunction_T;\n};\nexport type SideEffectFunction_T = (ctx:C,e:Event_T,self:Interpreter_T,originalContext:C)=>void;\nexport interface ContextMutation_T {\n type: 'ContextMutation';\n fn: ContextMutationFunction_T;\n};\nexport type ContextMutationFunction_T = (ctx:C,e:Event_T,self:Interpreter_T)=>C;\nexport interface Peer_T {\n type: 'SetPeer' | 'SetPeers' | 'AddPeers';\n name: string;\n peerCreationFunction: PeerCreationFunction_T\n};\nexport type PeerCreationFunction_T = (ctx:C,e:Event_T,self:Interpreter_T) => Interpreter_T | Array>;\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} };\nexport const Peer = function(name:string, peerCreationFunction:PeerCreationFunction_T) : Peer_T{ return {type:'SetPeer', name, peerCreationFunction}; }\nexport const Peers = function(name:string, peerCreationFunction:PeerCreationFunction_T) : Peer_T{ return {type:'SetPeers', name, peerCreationFunction}; }\nexport const AddPeers = function(name:string, peerCreationFunction:PeerCreationFunction_T) : Peer_T{ return {type:'AddPeers', name, peerCreationFunction}; }\n\n\nexport interface Interpreter_T {\n machine: Machine_T;\n state: string;\n context: C;\n peers: Record | Array>>;\n peerSubscriptionIds: Map,string>;\n eventQueue:Array;\n subscriptionsToEvents: Record>; // called upon every event\n subscriptionsToState: Record>; // every time state changes, even if it's transient\n subscriptionsToSettledState: Record>; // only called when tick settles\n isTransitioning: boolean;\n isPaused: boolean;\n start: ()=>Interpreter_T;\n}\n\n/**\n * Description placeholder\n *\n * @export\n * @param {Machine_T} machine\n * @param {any} initialContext\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 //@ts-expect-error\n const interpreter : Interpreter_T = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, peers:{}, peerSubscriptionIds:new Map(), subscriptionsToEvents: {}, subscriptionsToState: {}, subscriptionsToSettledState: {}, isPaused: true};\n interpreter.start = ()=>{ start(interpreter); return interpreter; }\n send(interpreter, ['entry', null] );\n return interpreter;\n}\nexport function start(interpreter:Interpreter_T){\n if(interpreter.isPaused === true){\n interpreter.isPaused = false;\n processEvents(interpreter);\n }\n}\nexport function pause(interpreter:Interpreter_T){\n if(interpreter.isPaused === false){\n interpreter.isPaused = true;\n }\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.subscriptionsToSettledState).forEach((callbackFunction)=>{ callbackFunction(interpreter); });\n}\nfunction processNextEvent(interpreter:Interpreter_T){\n const event = interpreter.eventQueue.shift();\n if(typeof event !== 'undefined'){\n const state = getState(interpreter);\n const eventReactionCouplings = getMatchingEventReactionCouplings(state, event);\n const reactions = eventReactionCouplings\n .map((eventReactionCoupling)=>eventReactionCoupling.reactions)\n .flat();\n const {sideEffects, contextMutations, peerings, goto_} = categorizeReactions(reactions);\n // save the current context, before it's mutated, so as to pass it to sideEffects below:\n const originalContext = interpreter.context;\n // must process contextMutations in-series:\n contextMutations.forEach((contextMutation:ContextMutation_T)=>{\n interpreter.context = contextMutation.fn(interpreter.context, event, interpreter);\n });\n // processing of `goto` must be last:\n if(goto_ !== null){\n send(interpreter, ['exit', null]);\n interpreter.state = goto_.targetStateName;\n // run subscription-to-state callbacks (can be in parallel), since state just changed, possibly transiently (depends on whether the loop in `processEvents()` runs again):\n Object.values(interpreter.subscriptionsToState).forEach((callbackFunction)=>{ callbackFunction(event, interpreter); });\n send(interpreter, ['entry', null]);\n }\n // now that \"internal\" stuff has been run, we can run \"external\" stuff:\n // process peerings (possibly in parallel):\n peerings.forEach((peering)=>{\n if(peering.type === 'SetPeer'){\n setPeer(interpreter, peering.name, peering.peerCreationFunction(interpreter.context, event, interpreter) as Interpreter_T);\n }\n else if(peering.type === 'SetPeers'){\n setPeers(interpreter, peering.name, peering.peerCreationFunction(interpreter.context, event, interpreter) as Array>);\n }\n else if(peering.type === 'AddPeers'){\n addPeers(interpreter, peering.name, peering.peerCreationFunction(interpreter.context, event, interpreter) as Array>);\n }\n });\n // run subscription-to-events callbacks (can be in parallel), since an event just happened:\n Object.values(interpreter.subscriptionsToEvents).forEach((callbackFunction)=>{ callbackFunction(event, interpreter); });\n // can process sideEffects in parallel (though we currently don't due to the overhead of doing so in Node.js):\n // they're processed *after* the context changes, since that's what most sideEffects would be interested in; but nevertheless the original context is passed in case this sideEffect needs it:\n sideEffects.forEach((sideEffect)=>{\n sideEffect.fn(interpreter.context, event, interpreter, originalContext);\n });\n }\n}\nfunction categorizeReactions(reactions:Array>) : {sideEffects:Array>, contextMutations:Array>, peerings:Array>, goto_:Goto_T|null}{\n let \n sideEffects:Array> = [], \n contextMutations:Array> = [], \n peerings: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 === 'SetPeer'){\n peerings.push(reaction);\n }\n else if(reaction.type === 'Goto'){\n goto_ = reaction;\n }\n });\n return {sideEffects, contextMutations, peerings, goto_};\n}\n\nexport type EventsSubscriptionCallbackFunction_T = (e:Event_T, self:Interpreter_T)=>void;\nexport type StateSubscriptionCallbackFunction_T = (e:Event_T, self:Interpreter_T)=>void;\nexport type SettledStateSubscriptionCallbackFunction_T = (self:Interpreter_T)=>void; // we don't pass an event, because these only run once state settles, so a whole chain of events could have been responsible for that; it's unlikely a subscriber is interested only in the final one\n// TODO: add subscribeToContext and subscribeToSettledContext functions, to get only changes to context, regardless of events happening or state changing\nlet subscriptionId : number = 0;\nexport function subscribe(interpreter:Interpreter_T, callback:SettledStateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToSettledState[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport const subscribeToSettledState = subscribe;\nexport function subscribeToState(interpreter:Interpreter_T, callback:StateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToState[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport function subscribeToEvents(interpreter:Interpreter_T, callback:StateSubscriptionCallbackFunction_T){\n subscriptionId++;\n interpreter.subscriptionsToEvents[subscriptionId.toString()] = callback;\n return subscriptionId.toString();\n}\nexport function unsubscribe(interpreter:Interpreter_T, subscriptionId:string){\n delete interpreter.subscriptionsToSettledState[subscriptionId.toString()];\n delete interpreter.subscriptionsToState[subscriptionId.toString()];\n delete interpreter.subscriptionsToEvents[subscriptionId.toString()];\n}\n\nexport function setPeer(self:Interpreter_T, name:string, peer:Interpreter_T){\n // if it exists, unsubscribe:\n if(self.peers.hasOwnProperty(name)){\n unsubscribe(self, self.peerSubscriptionIds.get(self.peers[name] as Interpreter_T));\n }\n self.peers[name] = peer;\n const subscriptionId = subscribeToEvents(peer, (e, peer)=>{\n // TODO: ensure there's no faulty logic in having this `if`:\n // this `if` prevents infinite loops due to mutually-subscribed peers (cyclical dependencies):\n if(self.isTransitioning === false){\n send(self, [name+'.'+e[0], e[1]]);\n }\n });\n self.peerSubscriptionIds.set(peer, subscriptionId);\n}\nexport function setPeers(self:Interpreter_T, name:string, peers:Array>){\n // if any exist, unsubscribe:\n if(self.peers.hasOwnProperty(name)){\n (self.peers[name] as Array>).forEach(peer => {\n unsubscribe(self, self.peerSubscriptionIds.get(peer));\n });\n }\n self.peers[name] = peers;\n peers.forEach((peer)=>{\n const subscriptionId = subscribeToEvents(peer, (e, peer)=>{\n // TODO: ensure there's no faulty logic in having this `if`:\n // this `if` prevents infinite loops due to mutually-subscribed peers (cyclical dependencies):\n if(self.isTransitioning === false){\n send(self, [name+'.'+e[0], e[1]]);\n }\n });\n self.peerSubscriptionIds.set(peer, subscriptionId);\n });\n}\nexport function addPeers(self:Interpreter_T, name:string, peers:Array>){\n // if none exist, initialize with empty array:\n if(!self.peers.hasOwnProperty(name)){\n self.peers[name] = [];\n }\n (self.peers[name] as Array>).concat(peers);\n peers.forEach((peer)=>{\n const subscriptionId = subscribeToEvents(peer, (e, peer)=>{\n // TODO: ensure there's no faulty logic in having this `if`:\n // this `if` prevents infinite loops due to mutually-subscribed peers (cyclical dependencies):\n if(self.isTransitioning === false){\n send(self, [name+'.'+e[0], e[1]]);\n }\n });\n self.peerSubscriptionIds.set(peer, subscriptionId);\n });\n}\n\n/*\nexport function useMachine(machine, options){\n return useMemo(()=>interpret(AppMachine, {context:{}}),[]);\n}\n*/"], + "mappings": "AAkCO,IAAMA,EAAU,YAAeC,EAAyC,CAAE,MAAO,CAAC,OAAAA,CAAM,CAAG,EACrFC,EAAQ,SAAYC,KAAgBC,EAAuE,CAAE,MAAO,CAAC,KAAAD,EAAM,uBAAAC,CAAsB,CAAG,EACpJC,EAAK,SAAYC,KAAqBC,EAA6D,CAAE,MAAO,CAAC,UAAAD,EAAW,UAAAC,CAAS,CAAG,EACpIC,EAAa,SAAYC,EAA6C,CAAE,MAAO,CAAC,KAAK,aAAc,GAAAA,CAAE,CAAG,EACxGC,EAAO,SAASC,EAAiC,CAAE,MAAO,CAAC,KAAK,O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AAI,EAAmC,OAAOsD,CAAK,EAC/DA,EAAM,QAASF,GAAO,CACpB,IAAMR,EAAiBK,EAAkBG,EAAM,CAACC,EAAGD,IAAO,CAGrDD,EAAK,kBAAoB,IAC1B/B,EAAK+B,EAAM,CAACnD,EAAK,IAAIqD,EAAE,CAAC,EAAGA,EAAE,CAAC,CAAC,CAAC,CAEpC,CAAC,EACDF,EAAK,oBAAoB,IAAIC,EAAMR,CAAc,CACnD,CAAC,CACH", + "names": ["Machine", "states", "State", "name", "eventReactionCouplings", "On", "eventName", "reactions", "SideEffect", "fn", "Goto", "targetStateName", "Context", "Peer", "peerCreationFunction", "Peers", "AddPeers", "Interpreter", "machine", "initialContext", "initialStateName", "interpreter", "start", "send", "processEvents", "pause", "getState", "state", "getMatchingEventReactionCouplings", "event", "eventReactionCoupling", "enqueue", "processNextEvent", "callbackFunction", "sideEffects", "contextMutations", "peerings", "goto_", "categorizeReactions", "originalContext", "contextMutation", "peering", "setPeer", "setPeers", "addPeers", "sideEffect", "reaction", "subscriptionId", "subscribe", "callback", "subscribeToSettledState", "subscribeToState", "subscribeToEvents", "unsubscribe", "self", "peer", "e", "peers"] }