UNPKG

@launchmenu/core

Version:

An environment for visual keyboard controlled applets

56 lines 2 kB
import { ICommandState } from "./_types/ICommandState"; import { Field, IDataHook } from "model-react"; import { Resource } from "./dependencies/Resource"; import { ICommandMetadata } from "./_types/ICommandMetadata"; import { ICommand } from "./_types/ICommand"; /** * A base class for commands */ export declare abstract class Command implements ICommand { abstract metadata: ICommandMetadata; protected state: Field<ICommandState>; protected readonly dependencies: Resource[]; protected queue: { type: "execute" | "revert"; promise: Promise<void>; resolve: () => void; reject: (error: any) => void; dependencies: Promise<() => void>; }[]; /** * Executes the command * @returns A promise that resolves once execution finished */ execute(): Promise<void>; /** * Reverts the command * @returns A promise that resolves once reverting finished */ revert(): Promise<void>; /** * Adds a request to the queue * @param type The type of request to add * @returns The promise that resolves once the request is handled */ protected addQueue(type: "execute" | "revert"): Promise<void>; /** * Dispatches another execute or revert request if any remain */ protected dispatch(): Promise<void>; /** * Acquires the dependencies * @returns A function that can be used to release the dependencies */ protected acquireDependencies(): Promise<() => void>; /** * Retrieves the state of the command * @param hook The hook to subscribe to changes * @returns The state of the command */ getState(hook?: IDataHook): ICommandState; /** The code to call on execute */ protected abstract onExecute(): void | Promise<void>; /** The code to call on revert */ protected abstract onRevert(): void | Promise<void>; } //# sourceMappingURL=Command.d.ts.map