import { IStateMachineComponents } from "./susi-state-machine" ; export abstract class State { protected allowedStateTransitions : Map < StateName , State > ; constructor ( protected components , public name ) { this . allowedStateTransitions = new Map < StateName , State > ( ) ; } public abstract onEnter ( ) ; public abstract onExit ( ) ; protected transition ( state ) { if ( ! this . canTransition ( state ) ) { console . error ( `Invalid transition to state: ${ state }` ) ; return ; } console . log ( `transiting to state: ${ state . name }` ) ; this . onExit ( ) ; state . onEnter ( ) ; } private canTransition ( state ) { return this . allowedStateTransitions . has ( state . name ) ; } public set AllowedStateTransitions ( states ) { this . allowedStateTransitions = states ; } }