From 9f3fa470bcccfdee0db090be545f738cc0846b9c Mon Sep 17 00:00:00 2001 From: John Haugeland Date: Thu, 12 May 2022 18:36:24 -0700 Subject: [PATCH] Active flag hooks, fixes StoneCypher/fsl#716 --- benchmark/results/general.chart.html | 14 +- benchmark/results/general.json | 130 +- dist/es6/jssm-dot.js | 15333 ++++++++++++++++++++++++- dist/es6/jssm.d.ts | 2 + dist/es6/jssm.js | 56 +- dist/jssm.es5.cjs.js | 2 +- dist/jssm.es5.cjs.nonmin.js | 56 +- dist/jssm.es5.iife.js | 2 +- dist/jssm.es5.iife.nonmin.js | 56 +- docs/docs/assets/search.js | 2 +- docs/docs/classes/Machine.html | 2 +- docs/docs/modules.html | 2 +- jssm.d.ts | 2 + src/buildjs/load_local.html | 11 + src/buildjs/local_fg_bench.html | 38 + src/ts/jssm.ts | 112 +- 16 files changed, 15643 insertions(+), 177 deletions(-) create mode 100644 src/buildjs/load_local.html create mode 100644 src/buildjs/local_fg_bench.html diff --git a/benchmark/results/general.chart.html b/benchmark/results/general.chart.html index a9a8f409..c2c93d8f 100644 --- a/benchmark/results/general.chart.html +++ b/benchmark/results/general.chart.html @@ -28,7 +28,7 @@
- +
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Machine<mDT>

Type parameters

  • mDT

Hierarchy

  • Machine

Index

Constructors

Properties

Methods

Constructors

  • new Machine<mDT>(__namedParameters: JssmGenericConfig<mDT>): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • __namedParameters: JssmGenericConfig<mDT>

    Returns Machine<mDT>

Properties

_actions: Map<string, Map<string, number>>
_any_action_hook: Function
_any_transition_hook: Function
_arrange_declaration: string[][]
_arrange_end_declaration: string[][]
_arrange_start_declaration: string[][]
_dot_preamble: string
_edge_map: Map<string, Map<string, number>>
_edges: JssmTransition<mDT>[]
_entry_hooks: Map<string, Function>
_exit_hooks: Map<string, Function>
_flow: FslDirection
_forced_transition_hook: Function
_fsl_version?: string
_global_action_hooks: Map<string, Function>
_graph_layout: JssmLayout
_has_basic_hooks: boolean
_has_entry_hooks: boolean
_has_exit_hooks: boolean
_has_hooks: boolean
_has_named_hooks: boolean
_hooks: Map<string, Function>
_machine_author?: string[]
_machine_comment?: string
_machine_contributor?: string[]
_machine_definition?: string
_machine_language?: string
_machine_license?: string
_machine_name?: string
_machine_version?: string
_main_transition_hook: Function
_named_hooks: Map<string, Function>
_named_transitions: Map<string, number>
_raw_state_declaration?: Object[]
_reverse_action_targets: Map<string, Map<string, number>>
_reverse_actions: Map<string, Map<string, number>>
_standard_transition_hook: Function
_state: string
_state_declarations: Map<string, JssmStateDeclaration>
_states: Map<string, JssmGenericState>
_theme: FslTheme

Methods

  • _new_state(state_config: JssmGenericState): string
  • Parameters

    • state_config: JssmGenericState

    Returns string

  • action(actionName: string, newData?: mDT): boolean
  • Parameters

    • actionName: string
    • Optional newData: mDT

    Returns boolean

  • actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • current_action_edge_for(action: string): JssmTransition<mDT>
  • Parameters

    • action: string

    Returns JssmTransition<mDT>

  • current_action_for(action: string): number
  • Parameters

    • action: string

    Returns number

  • dot_preamble(): string
  • edges_between(from: string, to: string): JssmTransition<mDT>[]
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>[]

  • flow(): FslDirection
  • force_transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • fsl_version(): string
  • get_transition_by_state_names(from: string, to: string): number
  • Parameters

    • from: string
    • to: string

    Returns number

  • graph_layout(): string
  • has_completes(): boolean
  • has_state(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • has_terminals(): boolean
  • has_unenterables(): boolean
  • hook(from: string, to: string, handler: Function): Machine<mDT>
  • hook_action(from: string, to: string, action: string, handler: Function): Machine<mDT>
  • Parameters

    • from: string
    • to: string
    • action: string
    • handler: Function

    Returns Machine<mDT>

  • hook_any_action(handler: Function): Machine<mDT>
  • hook_any_transition(handler: Function): Machine<mDT>
  • hook_entry(to: string, handler: Function): Machine<mDT>
  • hook_exit(from: string, handler: Function): Machine<mDT>
  • hook_forced_transition(handler: Function): Machine<mDT>
  • hook_global_action(action: string, handler: Function): Machine<mDT>
  • hook_main_transition(handler: Function): Machine<mDT>
  • hook_standard_transition(handler: Function): Machine<mDT>
  • is_complete(): boolean
  • is_final(): boolean
  • is_terminal(): boolean
  • is_unenterable(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • list_actions(): string[]
  • list_edges(): JssmTransition<mDT>[]
  • list_entrances(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exit_actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exits(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_named_transitions(): Map<string, number>
  • list_states_having_action(whichState: string): string[]
  • Parameters

    • whichState: string

    Returns string[]

  • list_transitions(whichState?: string): JssmTransitionList
  • Parameters

    • whichState: string = ...

    Returns JssmTransitionList

  • lookup_transition_for(from: string, to: string): JssmTransition<mDT>
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>

  • machine_author(): string[]
  • machine_comment(): string
  • machine_contributor(): string[]
  • machine_definition(): string
  • machine_language(): string
  • machine_license(): string
  • machine_name(): string
  • machine_state(): JssmMachineInternalState<mDT>
  • Returns JssmMachineInternalState<mDT>

  • machine_version(): string
  • probabilistic_histo_walk(n: number): Map<string, number>
  • Parameters

    • n: number

    Returns Map<string, number>

  • probabilistic_transition(): boolean
  • probabilistic_walk(n: number): string[]
  • Parameters

    • n: number

    Returns string[]

  • probable_action_exits(whichState?: string): any[]
  • Parameters

    • whichState: string = ...

    Returns any[]

  • probable_exits_for(whichState: string): JssmTransition<mDT>[]
  • Parameters

    • whichState: string

    Returns JssmTransition<mDT>[]

  • raw_state_declarations(): Object[]
  • set_hook(HookDesc: HookDescription): void
  • Parameters

    • HookDesc: HookDescription

    Returns void

  • sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • state(): string
  • state_declaration(which: string): JssmStateDeclaration
  • Parameters

    • which: string

    Returns JssmStateDeclaration

  • state_declarations(): Map<string, JssmStateDeclaration>
  • Returns Map<string, JssmStateDeclaration>

  • state_for(whichState: string): JssmGenericState
  • Parameters

    • whichState: string

    Returns JssmGenericState

  • state_is_complete(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_final(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_terminal(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • states(): string[]
  • theme(): FslTheme
  • transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • transition_impl(newStateOrAction: string, newData: mDT, wasForced: boolean, wasAction: boolean): boolean
  • Parameters

    • newStateOrAction: string
    • newData: mDT
    • wasForced: boolean
    • wasAction: boolean

    Returns boolean

  • valid_action(action: string, _newData?: mDT): boolean
  • Parameters

    • action: string
    • Optional _newData: mDT

    Returns boolean

  • valid_force_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

  • valid_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

Generated using TypeDoc

\ No newline at end of file +Machine | jssm
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Machine<mDT>

Type parameters

  • mDT

Hierarchy

  • Machine

Index

Constructors

Properties

Methods

Constructors

  • new Machine<mDT>(__namedParameters: JssmGenericConfig<mDT>): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • __namedParameters: JssmGenericConfig<mDT>

    Returns Machine<mDT>

Properties

_actions: Map<string, Map<string, number>>
_any_action_hook: Function
_any_transition_hook: Function
_arrange_declaration: string[][]
_arrange_end_declaration: string[][]
_arrange_start_declaration: string[][]
_dot_preamble: string
_edge_map: Map<string, Map<string, number>>
_edges: JssmTransition<mDT>[]
_entry_hooks: Map<string, Function>
_exit_hooks: Map<string, Function>
_flow: FslDirection
_forced_transition_hook: Function
_fsl_version?: string
_global_action_hooks: Map<string, Function>
_graph_layout: JssmLayout
_has_basic_hooks: boolean
_has_entry_hooks: boolean
_has_exit_hooks: boolean
_has_global_action_hooks: boolean
_has_hooks: boolean
_has_named_hooks: boolean
_has_transition_hooks: boolean
_hooks: Map<string, Function>
_machine_author?: string[]
_machine_comment?: string
_machine_contributor?: string[]
_machine_definition?: string
_machine_language?: string
_machine_license?: string
_machine_name?: string
_machine_version?: string
_main_transition_hook: Function
_named_hooks: Map<string, Function>
_named_transitions: Map<string, number>
_raw_state_declaration?: Object[]
_reverse_action_targets: Map<string, Map<string, number>>
_reverse_actions: Map<string, Map<string, number>>
_standard_transition_hook: Function
_state: string
_state_declarations: Map<string, JssmStateDeclaration>
_states: Map<string, JssmGenericState>
_theme: FslTheme

Methods

  • _new_state(state_config: JssmGenericState): string
  • Parameters

    • state_config: JssmGenericState

    Returns string

  • action(actionName: string, newData?: mDT): boolean
  • Parameters

    • actionName: string
    • Optional newData: mDT

    Returns boolean

  • actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • current_action_edge_for(action: string): JssmTransition<mDT>
  • Parameters

    • action: string

    Returns JssmTransition<mDT>

  • current_action_for(action: string): number
  • Parameters

    • action: string

    Returns number

  • dot_preamble(): string
  • edges_between(from: string, to: string): JssmTransition<mDT>[]
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>[]

  • flow(): FslDirection
  • force_transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • fsl_version(): string
  • get_transition_by_state_names(from: string, to: string): number
  • Parameters

    • from: string
    • to: string

    Returns number

  • graph_layout(): string
  • has_completes(): boolean
  • has_state(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • has_terminals(): boolean
  • has_unenterables(): boolean
  • hook(from: string, to: string, handler: Function): Machine<mDT>
  • hook_action(from: string, to: string, action: string, handler: Function): Machine<mDT>
  • Parameters

    • from: string
    • to: string
    • action: string
    • handler: Function

    Returns Machine<mDT>

  • hook_any_action(handler: Function): Machine<mDT>
  • hook_any_transition(handler: Function): Machine<mDT>
  • hook_entry(to: string, handler: Function): Machine<mDT>
  • hook_exit(from: string, handler: Function): Machine<mDT>
  • hook_forced_transition(handler: Function): Machine<mDT>
  • hook_global_action(action: string, handler: Function): Machine<mDT>
  • hook_main_transition(handler: Function): Machine<mDT>
  • hook_standard_transition(handler: Function): Machine<mDT>
  • is_complete(): boolean
  • is_final(): boolean
  • is_terminal(): boolean
  • is_unenterable(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • list_actions(): string[]
  • list_edges(): JssmTransition<mDT>[]
  • list_entrances(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exit_actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exits(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_named_transitions(): Map<string, number>
  • list_states_having_action(whichState: string): string[]
  • Parameters

    • whichState: string

    Returns string[]

  • list_transitions(whichState?: string): JssmTransitionList
  • Parameters

    • whichState: string = ...

    Returns JssmTransitionList

  • lookup_transition_for(from: string, to: string): JssmTransition<mDT>
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>

  • machine_author(): string[]
  • machine_comment(): string
  • machine_contributor(): string[]
  • machine_definition(): string
  • machine_language(): string
  • machine_license(): string
  • machine_name(): string
  • machine_state(): JssmMachineInternalState<mDT>
  • Returns JssmMachineInternalState<mDT>

  • machine_version(): string
  • probabilistic_histo_walk(n: number): Map<string, number>
  • Parameters

    • n: number

    Returns Map<string, number>

  • probabilistic_transition(): boolean
  • probabilistic_walk(n: number): string[]
  • Parameters

    • n: number

    Returns string[]

  • probable_action_exits(whichState?: string): any[]
  • Parameters

    • whichState: string = ...

    Returns any[]

  • probable_exits_for(whichState: string): JssmTransition<mDT>[]
  • Parameters

    • whichState: string

    Returns JssmTransition<mDT>[]

  • raw_state_declarations(): Object[]
  • set_hook(HookDesc: HookDescription): void
  • Parameters

    • HookDesc: HookDescription

    Returns void

  • sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • state(): string
  • state_declaration(which: string): JssmStateDeclaration
  • Parameters

    • which: string

    Returns JssmStateDeclaration

  • state_declarations(): Map<string, JssmStateDeclaration>
  • Returns Map<string, JssmStateDeclaration>

  • state_for(whichState: string): JssmGenericState
  • Parameters

    • whichState: string

    Returns JssmGenericState

  • state_is_complete(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_final(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_terminal(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • states(): string[]
  • theme(): FslTheme
  • transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • transition_impl(newStateOrAction: string, newData: mDT, wasForced: boolean, wasAction: boolean): boolean
  • Parameters

    • newStateOrAction: string
    • newData: mDT
    • wasForced: boolean
    • wasAction: boolean

    Returns boolean

  • valid_action(action: string, _newData?: mDT): boolean
  • Parameters

    • action: string
    • Optional _newData: mDT

    Returns boolean

  • valid_force_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

  • valid_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/docs/modules.html b/docs/docs/modules.html index c353c905..7a63e9a6 100644 --- a/docs/docs/modules.html +++ b/docs/docs/modules.html @@ -1 +1 @@ -jssm
Options
All
  • Public
  • Public/Protected
  • All
Menu

jssm

Index

Variables

histograph: Function = ...
seq: Function = ...
version: string = "5.61.1"
weighted_histo_key: Function = ...
weighted_rand_select: Function = ...
weighted_sample_select: Function = ...

Functions

  • arrow_direction(arrow: JssmArrow): JssmArrowDirection
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowDirection

  • arrow_left_kind(arrow: JssmArrow): JssmArrowKind
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowKind

  • arrow_right_kind(arrow: JssmArrow): JssmArrowKind
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowKind

  • compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>
  • Type parameters

    • mDT

    Parameters

    • tree: JssmParseTree

    Returns JssmGenericConfig<mDT>

  • make<mDT>(plan: string): JssmGenericConfig<mDT>
  • Type parameters

    • mDT

    Parameters

    • plan: string

    Returns JssmGenericConfig<mDT>

  • parse(input: string, options?: Object): any
  • Parameters

    • input: string
    • Optional options: Object

    Returns any

  • sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration
  • Parameters

    • state_decl: JssmStateDeclaration

    Returns JssmStateDeclaration

Generated using TypeDoc

\ No newline at end of file +jssm
Options
All
  • Public
  • Public/Protected
  • All
Menu

jssm

Index

Variables

histograph: Function = ...
seq: Function = ...
version: string = "5.61.1"
weighted_histo_key: Function = ...
weighted_rand_select: Function = ...
weighted_sample_select: Function = ...

Functions

  • arrow_direction(arrow: JssmArrow): JssmArrowDirection
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowDirection

  • arrow_left_kind(arrow: JssmArrow): JssmArrowKind
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowKind

  • arrow_right_kind(arrow: JssmArrow): JssmArrowKind
  • Parameters

    • arrow: JssmArrow

    Returns JssmArrowKind

  • compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>
  • Type parameters

    • mDT

    Parameters

    • tree: JssmParseTree

    Returns JssmGenericConfig<mDT>

  • make<mDT>(plan: string): JssmGenericConfig<mDT>
  • Type parameters

    • mDT

    Parameters

    • plan: string

    Returns JssmGenericConfig<mDT>

  • parse(input: string, options?: Object): any
  • Parameters

    • input: string
    • Optional options: Object

    Returns any

  • sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration
  • Parameters

    • state_decl: JssmStateDeclaration

    Returns JssmStateDeclaration

Generated using TypeDoc

\ No newline at end of file diff --git a/jssm.d.ts b/jssm.d.ts index b5b41746..74e23c59 100644 --- a/jssm.d.ts +++ b/jssm.d.ts @@ -42,6 +42,8 @@ declare class Machine { _has_named_hooks: boolean; _has_entry_hooks: boolean; _has_exit_hooks: boolean; + _has_global_action_hooks: boolean; + _has_transition_hooks: boolean; _hooks: Map; _named_hooks: Map; _entry_hooks: Map; diff --git a/src/buildjs/load_local.html b/src/buildjs/load_local.html new file mode 100644 index 00000000..edb700a5 --- /dev/null +++ b/src/buildjs/load_local.html @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/buildjs/local_fg_bench.html b/src/buildjs/local_fg_bench.html new file mode 100644 index 00000000..ce8c6bf9 --- /dev/null +++ b/src/buildjs/local_fg_bench.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ts/jssm.ts b/src/ts/jssm.ts index cf742518..5100091e 100644 --- a/src/ts/jssm.ts +++ b/src/ts/jssm.ts @@ -484,10 +484,13 @@ class Machine { _has_hooks : boolean; - _has_basic_hooks : boolean; - _has_named_hooks : boolean; - _has_entry_hooks : boolean; - _has_exit_hooks : boolean; + _has_basic_hooks : boolean; + _has_named_hooks : boolean; + _has_entry_hooks : boolean; + _has_exit_hooks : boolean; + _has_global_action_hooks : boolean; + _has_transition_hooks : boolean; + // no boolean for _has_any_transition_hook _hooks : Map; @@ -547,21 +550,22 @@ class Machine { this._raw_state_declaration = state_declaration || []; this._fsl_version = fsl_version; - this._arrange_declaration = arrange_declaration; + this._arrange_declaration = arrange_declaration; this._arrange_start_declaration = arrange_start_declaration; - this._arrange_end_declaration = arrange_end_declaration; + this._arrange_end_declaration = arrange_end_declaration; this._dot_preamble = dot_preamble; - this._theme = theme; - this._flow = flow; + this._theme = theme; + this._flow = flow; this._graph_layout = graph_layout; - this._has_hooks = false; - - this._has_basic_hooks = false; - this._has_named_hooks = false; - this._has_entry_hooks = false; - this._has_exit_hooks = false; + this._has_hooks = false; + this._has_basic_hooks = false; + this._has_named_hooks = false; + this._has_entry_hooks = false; + this._has_exit_hooks = false; + this._has_global_action_hooks = false; + this._has_transition_hooks = true; // no need for a boolean has any transition hook, as it's one or nothing, so just test that for undefinedness this._hooks = new Map(); @@ -1030,17 +1034,20 @@ class Machine { case 'hook': this._hooks.set(hook_name(HookDesc.from, HookDesc.to), HookDesc.handler); - this._has_hooks = true; + this._has_hooks = true; + this._has_basic_hooks = true; break; case 'named': this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler); - this._has_hooks = true; + this._has_hooks = true; + this._has_named_hooks = true; break; case 'global action': this._global_action_hooks.set(HookDesc.action, HookDesc.handler); - this._has_hooks = true; + this._has_hooks = true; + this._has_global_action_hooks = true; break; case 'any action': @@ -1050,17 +1057,20 @@ class Machine { case 'standard transition': this._standard_transition_hook = HookDesc.handler; - this._has_hooks = true; + this._has_transition_hooks = true; + this._has_hooks = true; break; case 'main transition': this._main_transition_hook = HookDesc.handler; - this._has_hooks = true; + this._has_transition_hooks = true; + this._has_hooks = true; break; case 'forced transition': this._forced_transition_hook = HookDesc.handler; - this._has_hooks = true; + this._has_transition_hooks = true; + this._has_hooks = true; break; case 'any transition': @@ -1070,12 +1080,14 @@ class Machine { case 'entry': this._entry_hooks.set(HookDesc.to, HookDesc.handler); - this._has_hooks = true; + this._has_hooks = true; + this._has_entry_hooks = true; break; case 'exit': this._exit_hooks.set(HookDesc.from, HookDesc.handler); - this._has_hooks = true; + this._has_hooks = true; + this._has_exit_hooks = true; break; default: @@ -1225,9 +1237,11 @@ class Machine { } else { if (this.valid_transition(newStateOrAction, newData)) { - valid = true; - trans_type = this.edges_between(this._state, newStateOrAction)[0].kind; // TODO this won't do the right thing if various edges have different types - newState = newStateOrAction; + if (this._has_transition_hooks) { + trans_type = this.edges_between(this._state, newStateOrAction)[0].kind; // TODO this won't do the right thing if various edges have different types + } + valid = true; + newState = newStateOrAction; } } @@ -1258,35 +1272,41 @@ class Machine { } // 4. exit hook - const maybe_ex_hook: Function | undefined = this._exit_hooks.get(this._state); + if (this._has_exit_hooks) { + const maybe_ex_hook: Function | undefined = this._exit_hooks.get(this._state); - if (maybe_ex_hook !== undefined) { - if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) { - return false; + if (maybe_ex_hook !== undefined) { + if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) { + return false; + } } } // 5. named transition / action hook - if (wasAction) { + if (this._has_named_hooks) { + if (wasAction) { - const nhn: string = named_hook_name(this._state, newState, newStateOrAction), - n_maybe_hook = this._named_hooks.get(nhn); + const nhn: string = named_hook_name(this._state, newState, newStateOrAction), + n_maybe_hook = this._named_hooks.get(nhn); - if (n_maybe_hook !== undefined) { - if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) { - return false; + if (n_maybe_hook !== undefined) { + if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) { + return false; + } } - } + } } // 6. regular hook - const hn: string = hook_name(this._state, newState), - maybe_hook: Function | undefined = this._hooks.get(hn); + if (this._has_basic_hooks) { + const hn: string = hook_name(this._state, newState), + maybe_hook: Function | undefined = this._hooks.get(hn); - if (maybe_hook !== undefined) { - if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction? newStateOrAction : undefined }) === false) { - return false; + if (maybe_hook !== undefined) { + if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction? newStateOrAction : undefined }) === false) { + return false; + } } } @@ -1326,11 +1346,13 @@ class Machine { } // 8. entry hook - const maybe_en_hook: Function | undefined = this._entry_hooks.get(newState); + if (this._has_entry_hooks) { + const maybe_en_hook: Function | undefined = this._entry_hooks.get(newState); - if (maybe_en_hook !== undefined) { - if (maybe_en_hook({ to: newState, forced: wasForced }) === false) { - return false; + if (maybe_en_hook !== undefined) { + if (maybe_en_hook({ to: newState, forced: wasForced }) === false) { + return false; + } } }