title | isDefaultIndex | generated |
---|---|---|
StateMachineConfig |
false |
true |
import MemberInfo from '@site/src/components/MemberInfo'; import GenerationInfo from '@site/src/components/GenerationInfo'; import MemberDescription from '@site/src/components/MemberDescription';
The config object used to instantiate a new FSM instance.
interface StateMachineConfig<T extends string, Data = undefined> {
readonly transitions: Transitions<T>;
onTransitionStart?: OnTransitionStartFn<T, Data>;
onTransitionEnd?: OnTransitionEndFn<T, Data>;
onError?: OnTransitionErrorFn<T>;
}
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/transitions#transitions'>Transitions</a><T>
} />
Defines the available states of the state machine as well as the permitted transitions from one state to another.
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionstartfn'>OnTransitionStartFn</a><T, Data>
} />
Called before a transition takes place. If the function resolves to false
or a string, then the transition
will be cancelled. In the case of a string, the string (error message) will be forwarded to the onError handler.
If this function returns a value resolving to true
or void
(no return value), then the transition
will be permitted.
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionendfn'>OnTransitionEndFn</a><T, Data>
} />
Called after a transition has taken place.
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionerrorfn'>OnTransitionErrorFn</a><T>
} />
Called when a transition is prevented and the onTransitionStart
handler has returned an
error message.
Called before a transition takes place. If the function resolves to false
or a string, then the transition
will be cancelled. In the case of a string, the string (error message) will be forwarded to the onError handler.
If this function returns a value resolving to true
or void
(no return value), then the transition
will be permitted.
type OnTransitionStartFn<T extends string, Data> = (
fromState: T,
toState: T,
data: Data,
) => boolean | string | void | Promise<boolean | string | void> | Observable<boolean | string | void>
Called when a transition is prevented and the onTransitionStart
handler has returned an
error message.
type OnTransitionErrorFn<T extends string> = (
fromState: T,
toState: T,
message?: string,
) => void | Promise<void> | Observable<void>
Called after a transition has taken place.
type OnTransitionEndFn<T extends string, Data> = (
fromState: T,
toState: T,
data: Data,
) => void | Promise<void> | Observable<void>