-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fsm): update action naming conventions and enhance event han…
…dling in state transitions BREAKING CHANGE: all name of type ActionName in class `actionRecord_` changed
- Loading branch information
Showing
4 changed files
with
48 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
export interface StateEventDetail<S, E> { | ||
export interface StateEventDetail<S extends string, E extends string> { | ||
from: S; | ||
event: E; | ||
event: E | 'reset'; | ||
to: S; | ||
} | ||
|
||
export type StateRecord<S extends string, E extends string> = Partial<Record<S | '_all', Partial<Record<E, S>>>>; | ||
export type StateRecord<S extends string, E extends string> = Partial<Record<S, Partial<Record<E | 'reset', S>>>>; | ||
|
||
export type Action<S extends string, E extends string> = (eventDetail?: StateEventDetail<S, E>) => MaybePromise<void>; | ||
export type Action<S extends string, E extends string> = (eventDetail?: StateEventDetail<S, E | 'reset'>) => MaybePromise<void>; | ||
|
||
export type ActionName<S extends string, E extends string> = | ||
| `on_${E}` | ||
| `on_state_exit` | ||
| `on_state_enter` | ||
| `on_${S}_exit` | ||
| `on_${S}_enter` | ||
| `on_${S}_${E}` | ||
| `on_all_${E}`; | ||
| `on_event_${E}` | ||
| `on_any_state_exit` | ||
| `on_any_state_enter` | ||
| `on_state_${S}_exit` | ||
| `on_state_${S}_enter` | ||
| `on_state_${S}_event_${E}`; | ||
|
||
export type ActionRecord<S extends string, E extends string> = Partial<Record<ActionName<S, E>, Action<S, E>>>; | ||
export type ActionRecord<S extends string, E extends string> = Partial<Record<ActionName<S, E | 'reset'>, Action<S, E | 'reset'>>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters