diff --git a/ui/element/src/reactive-controllers/finite-state-machine.ts b/ui/element/src/reactive-controllers/finite-state-machine.ts index ed6d44eda..1fc9389f2 100644 --- a/ui/element/src/reactive-controllers/finite-state-machine.ts +++ b/ui/element/src/reactive-controllers/finite-state-machine.ts @@ -1,41 +1,26 @@ -import {FiniteStateMachine, type StateContext, type MachineConfig} from '@alwatr/fsm'; +import {FiniteStateMachine, type FsmConfig} from '@alwatr/fsm'; -import {nothing, ReactiveController} from '../lit.js'; +import {nothing, type ReactiveController} from '../lit.js'; import type {LoggerMixinInterface} from '../mixins/logging.js'; import type {StringifyableRecord} from '@alwatr/type'; -export declare class AlwatrElementHostController< - TState extends string, - TEventId extends string -> extends LoggerMixinInterface { - stateUpdate(state: StateContext): void; -} - export class FiniteStateMachineController< TState extends string, TEventId extends string, TContext extends StringifyableRecord - > - extends FiniteStateMachine - implements ReactiveController { + > extends FiniteStateMachine implements ReactiveController { constructor( - private _host: AlwatrElementHostController, - config: Readonly>, + private _host: LoggerMixinInterface, + config: Readonly>, ) { super(config); - this._logger.logMethodArgs('constructor', config); this._host.addController(this); } - protected override setState(to: TState, by: TEventId | 'INIT' ): void { - super.setState(to, by); - this._host.stateUpdate.call(this._host, this.state); - } - render(states: {[P in TState]?: (() => unknown) | TState}): unknown { - this._logger.logMethodArgs('render', this.state.to); - let renderFn = states[this.state.to]; + this._logger.logMethodArgs('render', this.state.target); + let renderFn = states[this.state.target]; if (typeof renderFn === 'string') { renderFn = states[renderFn]; } @@ -47,6 +32,11 @@ export class FiniteStateMachineController< } hostUpdate(): void { - this._host.setAttribute('state', this.state.to); + this._host.setAttribute('state', this.state.target); + } + + protected override callFunction(fn?: () => T): T | void { + if (typeof fn !== 'function') return; + return fn.call(this._host); } }