Skip to content

Commit

Permalink
feat(fsm): add signalRecord to config
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadhonarvar authored and alimd committed Mar 17, 2023
1 parent eef7ef3 commit 1a35291
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/fsm/src/core.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export class FiniteStateMachine<

protected async setState(target: TState, by: TEventId): Promise<void> {
const state = (this.state = {
target: target,
target,
from: this.signal.getValue()?.target ?? target,
by,
});
13 changes: 12 additions & 1 deletion core/fsm/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {MaybeArray, MaybePromise, StringifyableRecord} from '@alwatr/type';


export interface FsmConfig<TState extends string, TEventId extends string, TContext extends StringifyableRecord> {
/**
* Machine ID (It is used in the state change signal identifier, so it must be unique).
@@ -54,6 +53,18 @@ export interface FsmConfig<TState extends string, TEventId extends string, TCont
};
};
};

/**
* A list of signals ...
*/
signalRecord?: {
[signalId: string]: {
actions?: MaybeArray<(...args: any[]) => MaybePromise<void>>;
transition?: keyof FsmConfig<TState, TEventId, TContext>['stateRecord'][
keyof FsmConfig<TState, TEventId, TContext>['stateRecord']
]['on'];
}
}
}

export interface StateContext<TState extends string, TEventId extends string> {

0 comments on commit 1a35291

Please sign in to comment.