diff --git a/packages/fsm/src/base.ts b/packages/fsm/src/base.ts index 1242fc4..e9df1da 100644 --- a/packages/fsm/src/base.ts +++ b/packages/fsm/src/base.ts @@ -33,21 +33,26 @@ export abstract class AlwatrFluxStateMachineBase { this.logger_.logMethod?.('resetToInitialState_'); + if (this.firstResetToInitialState__) { + this.firstResetToInitialState__ = false; + const eventDetail: StateEventDetail = {from: this.initialState_, event: 'reset', to: this.initialState_}; + this.execAction__(`on_state_${this.initialState_}_enter`, eventDetail); + return this.postTransition__(eventDetail); + } + // else { const from = this.message_.state; this.message_ = {state: this.initialState_}; - this.postTransition__({ - from, - event: 'reset', - to: this.initialState_, - }); + const eventDetail: StateEventDetail = {from, event: 'reset', to: this.initialState_}; + return this.postTransition__(eventDetail); } /** @@ -77,9 +82,6 @@ export abstract class AlwatrFluxStateMachineBase = {from: fromState, event, to: toState}; - if ((await this.shouldTransition_(eventDetail)) !== true) return; - - this.notify_({state: toState}); // message update but notify event delayed after execActions. this.postTransition__(eventDetail); } @@ -88,7 +90,7 @@ export abstract class AlwatrFluxStateMachineBase): Promise { - this.logger_.logMethodArgs?.('_transitioned', eventDetail); + this.logger_.logMethodArgs?.('postTransition__', eventDetail); await this.execAction__(`on_event_${eventDetail.event}`, eventDetail); @@ -108,7 +110,7 @@ export abstract class AlwatrFluxStateMachineBase, eventDetail: StateEventDetail): MaybePromise { const actionFn = this.actionRecord_[name]; if (typeof actionFn === 'function') { - this.logger_.logMethodArgs?.('_$execAction', name); + this.logger_.logMethodArgs?.('execAction__', name); return actionFn.call(this, eventDetail); } }