Skip to content

Commit

Permalink
refactor(fsm2): extends from AlwatrBaseSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadhonarvar authored and AliMD committed Jun 5, 2023
1 parent c5a725a commit 9049d2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions core/fsm2/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {createLogger, globalAlwatr} from '@alwatr/logger';
import {AlwatrBaseSignal} from '@alwatr/signal2';

import type {MaybePromise, SingleOrArray, Stringifyable} from '@alwatr/type';

globalAlwatr.registeredList.push({
name: '@alwatr/fsm',
version: _ALWATR_VERSION_,
});

export type ActionFn = (this: unknown) => MaybePromise<void>;
export type ConditionFn = (this: unknown) => boolean;

Expand Down Expand Up @@ -86,9 +81,11 @@ export type MachineConfig<StateName extends string, EventName extends string, Co
/**
* Finite State Machine Class
*/
export class FiniteStateMachine<Context extends Stringifyable, StateName extends string, EventName extends string> {
protected _logger = createLogger(`alwatr/fsm`);

export class FiniteStateMachine<
Context extends Stringifyable,
StateName extends string,
EventName extends string
> extends AlwatrBaseSignal<StateConfig<StateName, EventName>> {
/**
* Current state
*/
Expand All @@ -105,6 +102,7 @@ export class FiniteStateMachine<Context extends Stringifyable, StateName extends
*/
protected _config: MachineConfig<StateName, EventName, Context>,
) {
super('FiniteStateMachine', 'fsm');
this._logger.logMethodArgs?.('constructor', {_config});

this.context = _config.context;
Expand Down
2 changes: 1 addition & 1 deletion core/fsm2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"references": [
{"path": "../logger"},
{"path": "../type"},
{"path": "../signal"},
{"path": "../signal2"},
]
}

0 comments on commit 9049d2c

Please sign in to comment.