@player-ui/player
Version:
63 lines • 2.73 kB
TypeScript
import { SyncBailHook, SyncHook, SyncWaterfallHook } from "tapable-ts";
import type { NavigationFlow, NavigationFlowState, NavigationFlowEndState, NavigationFlowActionState, NavigationFlowAsyncActionState, NavigationFlowExternalState, NavigationFlowFlowState, NavigationFlowViewState } from "@player-ui/types";
import type { Logger } from "../../logger";
export interface NamedState {
/** The name of the navigation node */
name: string;
/** The nav node */
value: NavigationFlowState;
}
export interface TransitionOptions {
/** Ignore any validations or other signals preventing the transition from taking place */
force?: boolean;
}
export type TransitionFunction = (name: string, options?: TransitionOptions) => void;
export interface FlowInstanceHooks {
beforeStart: SyncBailHook<[
NavigationFlow
], NavigationFlow, Record<string, any>>;
/** A callback when the onStart node was present */
onStart: SyncHook<[any], Record<string, any>>;
/** A callback when the onEnd node was present */
onEnd: SyncHook<[any], Record<string, any>>;
/** A hook to intercept and block a transition */
skipTransition: SyncBailHook<[
NamedState | undefined
], boolean | undefined, Record<string, any>>;
/** A chance to manipulate the flow-node used to calculate the given transition used */
beforeTransition: SyncWaterfallHook<[
(NavigationFlowViewState | NavigationFlowFlowState | NavigationFlowActionState | NavigationFlowAsyncActionState | NavigationFlowExternalState),
string
], Record<string, any>>;
/** A chance to manipulate the flow-node calculated after a transition */
resolveTransitionNode: SyncWaterfallHook<[
NavigationFlowState
], Record<string, any>>;
/** A callback when a transition from 1 state to another was made */
transition: SyncHook<[
NamedState | undefined,
NamedState
], Record<string, any>>;
/** A callback to run actions after a transition occurs */
afterTransition: SyncHook<[FlowInstance], Record<string, any>>;
}
/** The Content navigation state machine */
export declare class FlowInstance {
private flow;
private log?;
private history;
private isTransitioning;
private flowPromise?;
readonly id: string;
currentState?: NamedState;
readonly hooks: FlowInstanceHooks;
constructor(id: string, flow: NavigationFlow, options?: {
/** Logger instance to use */
logger?: Logger;
});
/** Start the state machine */
start(): Promise<NavigationFlowEndState>;
transition(transitionValue: string, options?: TransitionOptions): void;
private pushHistory;
}
//# sourceMappingURL=flow.d.ts.map