StateMachineConfig

StateMachineConfig

OnTransitionStartFn

Package: @vendure/core File: types.ts

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.

Signature

type OnTransitionStartFn<T extends string, Data> = (
    fromState: T,
    toState: T,
    data: Data,
) => boolean | string | void | Promise<boolean | string | void> | Observable<boolean | string | void>

OnTransitionErrorFn

Package: @vendure/core File: types.ts

Called after a transition has taken place.

Signature

type OnTransitionErrorFn<T extends string> = (
    fromState: T,
    toState: T,
    message?: string,
) => void | Promise<void> | Observable<void>

OnTransitionEndFn

Package: @vendure/core File: types.ts

Called when a transition is prevented and the onTransitionStart handler has returned an error message.

Signature

type OnTransitionEndFn<T extends string, Data> = (
    fromState: T,
    toState: T,
    data: Data,
) => void | Promise<void> | Observable<void>

StateMachineConfig

Package: @vendure/core File: types.ts

The config object used to instantiate a new FSM instance.

Signature

interface StateMachineConfig<T extends string, Data = undefined> {
  readonly transitions: Transitions<T>;
  onTransitionStart?: OnTransitionStartFn<T, Data>;
  onTransitionEnd?: OnTransitionEndFn<T, Data>;
  onError?: OnTransitionErrorFn<T>;
}

Members

transitions

readonly property
type:
Transitions<T>
Defines the available states of the state machine as well as the permitted transitions from one state to another.

onTransitionStart

property
type:
OnTransitionStartFn<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.

onTransitionEnd

property
type:
OnTransitionEndFn<T, Data>
Called after a transition has taken place.

onError

property
Called when a transition is prevented and the onTransitionStart handler has returned an error message.