UNPKG

@vk-io/scenes

Version:

Scenes for the library vk-io

86 lines (85 loc) 1.98 kB
import { ISessionContext } from '../types'; import { ISceneContextOptions, ISceneContextEnterOptions, ISceneContextLeaveOptions, LastAction } from './scene.types'; import { IScene } from '../scenes'; export declare class SceneContext<S extends Record<string, unknown>> { /** * Lazy session for submodules * ```ts * ctx.scene.session.moduleFlag = true; * ``` */ session: ISessionContext; /** * Base namespace for user input * * ```ts * ctx.scene.username = myInputText; * ``` */ state: S; /** * Is the scene canceled, used in leaveHandler() * * ```ts * ctx.scene.leave({ * canceled: true * }); * ``` */ canceled: boolean; lastAction: LastAction; private context; private repository; /** * Controlled behavior leave */ leaving: boolean; private sessionKey; constructor(options: ISceneContextOptions); /** * Returns current scene */ get current(): IScene | undefined; /** * Enter to scene * * ```ts * ctx.scene.enter('signup'); * ctx.scene.enter('signup', { * silent: true, * state: { * username: 'Super_Developer' * } * }); * ``` */ enter(slug: string, options?: ISceneContextEnterOptions<S>): Promise<void>; /** * Reenter to current scene * * ```ts * ctx.scene.reenter(); * ``` */ reenter(): Promise<void>; /** * Leave from current scene * * ```ts * ctx.scene.leave(); * ctx.scene.leave({ * silent: true, * canceled: true * }); * ``` */ leave(options?: ISceneContextLeaveOptions): Promise<void>; /** * Reset state/session */ reset(): void; /** * Updates session and state is lazy */ private updateSession; }