Skip to content

Action

Class representing an action (decorated method) with execution state and control.

typescript
class Action<T extends object, Args extends any[] = unknown[]>

Generics: T — model type; Args — action method arguments.

Static: possibleState, actionFlag, abortedByLock

All possible state names; symbol used by @action; symbol for lock-induced abort.

Static: Action.create

Factory for a reactive (shallowReactive) Action instance. Not called directly; used internally.

Instance properties

PropertyTypeDescription
namestringAction (method) name
ownerModel<T>Owning model
stateActionStateNameCurrent state
abortControllerAbortController | nullWhen pending
argsArgs | never[]Last exec arguments
promisePromise<void> | nullCurrent run when pending
errorActionError | nullWhen error
abortReasonunknownWhen abort
isPending, isError, isReady, isLock, isAbortbooleanState flags

Instance methods

MethodDescription
is(...states): booleanWhether action is in any of the given states
validate(...args): Error[]Validates arguments (does not run exec)
exec(...args): Promise<void>Runs the action. Catches exceptions → ActionError in error. Optional last arg: AbortController.
abort(reason?): Promise<void>Cancels if pending
lock(): Promise<void>Locks; if pending, aborts with abortedByLock
unlock(): thisUnlocks (only when lock)
resetError(): thisClears error state (only when error)
toString(): stringAction name

Note: exec catches exceptions and puts them in error; try/catch around exec() will not catch those. Check action.error after awaiting or watch it.

See also: ActionLike, ActionError, Internal errors.

Released under the MIT License.