update dist

main
Avraham Sakal 2 years ago
parent 37aa932956
commit 688cfce36b

62
dist/index.d.ts vendored

@ -1,58 +1,58 @@
export type Event_T = [name: string, payload: any];
export interface Machine_T {
states: Array<State_T>;
export interface Machine_T<C> {
states: Array<State_T<C>>;
}
export interface State_T {
export interface State_T<C> {
name: string;
eventReactionCouplings: Array<EventReactionCouplings_T>;
eventReactionCouplings: Array<EventReactionCouplings_T<C>>;
}
export interface EventReactionCouplings_T {
export interface EventReactionCouplings_T<C> {
eventName: string;
reactions: Array<Reaction_T>;
reactions: Array<Reaction_T<C>>;
}
export type Reaction_T = SideEffect_T | ContextMutation_T | Goto_T;
export interface SideEffect_T {
export type Reaction_T<C> = SideEffect_T<C> | ContextMutation_T<C> | Goto_T;
export interface SideEffect_T<C> {
type: 'SideEffect';
fn: SideEffectFunction_T;
fn: SideEffectFunction_T<C>;
}
export type SideEffectFunction_T = (ctx: any, e: Event_T, self: Interpreter_T) => void;
export interface ContextMutation_T {
export type SideEffectFunction_T<C> = (ctx: C, e: Event_T, self: Interpreter_T<C>, originalContext: C) => void;
export interface ContextMutation_T<C> {
type: 'ContextMutation';
fn: ContextMutationFunction_T;
fn: ContextMutationFunction_T<C>;
}
export type ContextMutationFunction_T = (ctx: any, e: Event_T, self: Interpreter_T) => any;
export type ContextMutationFunction_T<C> = (ctx: C, e: Event_T, self: Interpreter_T<C>) => C;
export interface Goto_T {
type: 'Goto';
targetStateName: string;
}
export declare const Machine: (...states: Array<State_T>) => Machine_T;
export declare const State: (name: string, ...eventReactionCouplings: Array<EventReactionCouplings_T>) => State_T;
export declare const On: (eventName: string, ...reactions: Array<Reaction_T>) => EventReactionCouplings_T;
export declare const SideEffect: (fn: SideEffectFunction_T) => SideEffect_T;
export declare const Machine: <C>(...states: State_T<C>[]) => Machine_T<C>;
export declare const State: <C>(name: string, ...eventReactionCouplings: EventReactionCouplings_T<C>[]) => State_T<C>;
export declare const On: <C>(eventName: string, ...reactions: Reaction_T<C>[]) => EventReactionCouplings_T<C>;
export declare const SideEffect: <C>(fn: SideEffectFunction_T<C>) => SideEffect_T<C>;
export declare const Goto: (targetStateName: string) => Goto_T;
export declare const Context: (fn: ContextMutationFunction_T) => ContextMutation_T;
export interface Interpreter_T {
machine: Machine_T;
export declare const Context: <C>(fn: ContextMutationFunction_T<C>) => ContextMutation_T<C>;
export interface Interpreter_T<C> {
machine: Machine_T<C>;
state: string;
context: any;
context: C;
eventQueue: Array<Event_T>;
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
subscriptions: Record<string, SubscriptionCallbackFunction_T<C>>;
isTransitioning: boolean;
isPaused: boolean;
start: () => Interpreter_T;
start: () => Interpreter_T<C>;
}
/**
* 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 {any} initialContext
* @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;
export declare function Interpreter<C>(machine: Machine_T<C>, initialContext: any, initialStateName?: string): Interpreter_T<C>;
export declare function start<C>(interpreter: Interpreter_T<C>): void;
export declare function pause<C>(interpreter: Interpreter_T<C>): 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;
@ -63,10 +63,10 @@ export declare function pause(interpreter: Interpreter_T): void;
* whether to run a reaction at all. If an Event is received, and is specified to be applied on a past
* Tick, it is discarded.
*/
export declare function send(interpreter: Interpreter_T, event: Event_T): void;
export declare function send<C>(interpreter: Interpreter_T<C>, 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): string;
export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void;
export type SubscriptionCallbackFunction_T<C> = (self: Interpreter_T<C>) => void;
export declare function subscribe<C>(interpreter: Interpreter_T<C>, callback: SubscriptionCallbackFunction_T<C>): string;
export declare function unsubscribe<C>(interpreter: Interpreter_T<C>, subscriptionId: string): void;
export declare const Spawn: () => void;
export declare const Unspawn: () => void;

2
dist/index.js vendored

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

6
dist/index.js.map vendored

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