Skip to content

Commit

Permalink
コメントの追加と整理
Browse files Browse the repository at this point in the history
  • Loading branch information
sigprogramming committed Feb 3, 2025
1 parent e36de95 commit 95e6085
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sing/stateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type SetNextState<T extends StateDefinition[]> = <U extends StateId<T>>(

/**
* ステートマシンのステートを表すインターフェース。
*
* @template State このインターフェースを実装するステートの型。
* @template Input ステートが処理する入力の型。
* @template Context ステート間で共有されるコンテキストの型。
Expand All @@ -57,6 +58,7 @@ export interface State<

/**
* 入力を処理し、必要に応じて次のステートを設定する。
*
* @param payload `input`、`context`、`setNextState`関数を含むペイロード。
*/
process(payload: {
Expand All @@ -67,12 +69,14 @@ export interface State<

/**
* ステートに入ったときに呼び出される。
*
* @param context ステート間で共有されるコンテキスト。
*/
onEnter(context: Context): void;

/**
* ステートから出るときに呼び出される。
*
* @param context ステート間で共有されるコンテキスト。
*/
onExit(context: Context): void;
Expand All @@ -98,6 +102,7 @@ type InitialStateId<T extends StateDefinition[]> = T[number] extends infer U

/**
* ステートマシンを表すクラス。
*
* @template State ステートマシンのステートの型。
* @template Input ステートが処理する入力の型。
* @template Context ステート間で共有されるコンテキストの型。
Expand Down Expand Up @@ -143,6 +148,7 @@ export class StateMachine<
/**
* ステートの遷移を行う。
* このメソッドは副作用として、現在のステートの onExit を呼び出し、遷移後のステートの onEnter を呼び出す。
*
* @param id 遷移先のステートのID。
* @param factoryArgs 遷移先のステートのファクトリー関数の引数。
*/
Expand All @@ -160,6 +166,7 @@ export class StateMachine<

/**
* 現在のステートを使用して入力を処理し、必要に応じてステートの遷移を行う。
*
* @param input 処理する入力。
*/
process(input: Input) {
Expand All @@ -185,6 +192,9 @@ export class StateMachine<
}
}

/**
* ステートマシンを破棄する。
*/
dispose() {
if (this.isDisposed) {
throw new Error("Already disposed.");
Expand Down

0 comments on commit 95e6085

Please sign in to comment.