UNPKG

@eclipse-emfcloud/model-manager

Version:

Command-based model editing with undo/redo.

57 lines 2.91 kB
import { Command, CommandResult, CompoundCommandImpl } from '../core/command'; import { CommandProvider, PreconditionPredicate } from '../core/deferred-compound-command'; type GetModel<K> = Parameters<CommandProvider<K>>[0]; /** * Implementation of a compound command that permits deferred computation of its child * commands with up-front declaration of the scope of models that it will edit. */ export declare class DeferredCompoundCommand<K = string> extends CompoundCommandImpl<K> { private readonly commandProvider; private readonly precondition?; /** * The model IDs describing the scope of models that I will edit. */ private readonly _modelScope; /** * Whether I have prepared my child commands. This is tracked as a separate state * from my child commands because it cannot be inferred from them: my command * provider may provide no commands and moreover commands may be statically added * to me in the usual manner. */ private _prepared; /** * Initializes me with my scope and a function that prepares my child commands. * * @label my label, for presentation in the UI * @param scope the scope of models that it is anticipated will be covered by the command * when it is {@link prepare}d. This can be wider than what is eventually * required but should not be narrower. * @param commandProvider a function that provides an iterable over the commands to add and * execute when it comes time to execute * @param precondition an optional precondition mode to check the {@link canExecute} condition. * This may be the constant `'strict'` to prepare my child commands and check them, or a * predicate function to check without first having to prepare my commands. If omitted, * precondition check is optimistically sidelined, just returning `true` */ constructor(label: string, modelScope: K[], commandProvider: CommandProvider<K>, precondition?: ("strict" | PreconditionPredicate<K>) | undefined); canExecute(getModel: GetModel<K>): Promise<boolean>; execute(getModel: GetModel<K>): CommandResult<K>; /** * Query the scope of models edited by this command, including the set declared up-front * and declared by any commands already added, either statically or by the deferred provider. */ get modelScope(): K[]; /** * Query whether I have prepared my member commands from my deferred provider. */ isPrepared(): boolean; /** * Prepare myself for execution by obtaining and appending the late-provided commands. * * @param getModel the model accessor to pass to my command provider */ protected prepare(getModel: GetModel<K>): Promise<void>; protected validate(command: Command<K>): Command<K> | undefined; } export {}; //# sourceMappingURL=deferred-compound-command-impl.d.ts.map