@ActionState
Action state decorator. Temporarily enters a specified state during async execution, returns to the original state after.
Signature
function ActionState(name?: string): MethodDecoratorParameters
| Parameter | Description |
|---|---|
name | Temporary state name. Defaults to the method name if omitted. |
Behavior
class Doc extends FSM { @ActionState('saving') async save() { await persist() }}Running save():
- Record
old = this.state setState('saving')(note: directly to'saving', not aMiddleState)- Run the original method
- Success:
setState(old), return the result - Failure:
setState(old, err), throw the original error
- Success:
vs @ChangeState
@ChangeState | @ActionState | |
|---|---|---|
| Pre-execution validation | validates from | none |
| Post-execution state | new stable state to | returns to original |
| Intermediate | MiddleState (${action}ing) | directly name |
| In stateDiagram | yes | no |
| Failure rollback | to from | to original |
Sync method support
If the original method returns a sync value, behavior is the same (sync return, state restored):
@ActionState('refreshing')refresh() { return this.cache}Example
The dataFetch example uses @ActionState('retrying') to surface the retry-wait intermediate state.