@eclipse-emfcloud/model-manager
Version:
Command-based model editing with undo/redo.
69 lines • 3.98 kB
JavaScript
;
// *****************************************************************************
// Copyright (C) 2024 STMicroelectronics.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: MIT License which is
// available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: EPL-2.0 OR MIT
// *****************************************************************************
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDeferredCompoundCommand = createDeferredCompoundCommand;
exports.createStrictDeferredCompoundCommand = createStrictDeferredCompoundCommand;
const deferred_compound_command_impl_1 = require("../impl/deferred-compound-command-impl");
/**
* Create a compound command that dynamically computes its child commands, just in
* time when executed. Because the determination of its member commands is deferred,
* the deferred compound requires up-front declaration of the `scope` of commands that
* it is intended to edit, so that it may exclude concurrent modifications of those
* models while its own execution is pending. The `children` eventually computed need
* not actually modify all models in this `scope` and they should not modify more
* models than are declared in the `scope`, which could result in unpredictable
* interference with other commands concurrently executed.
*
* While it is not anticipated to be typical usage, the resulting compound command
* does support the explicit addition of child commands in addition to the deferred
* provision of children. Any overlap or other interference between commands statically
* and dynamically added is the responsibility of the client.
*
* @template <K> the model ID type
*
* @param label a label for the compound command, suitable for presentation in some UI
* @param scope the IDs of models that the compound command will edit
* @param children a function providing the children to add to the compound just in time
* for them to be executed
* @param precondition an optional predicate function to compute, without having to create
* them, whether the commands to be provided for execution will be executable.
* If omitted, it is assumed that the compound overall will be able to be executed
*/
function createDeferredCompoundCommand(label, scope, children, precondition) {
return new deferred_compound_command_impl_1.DeferredCompoundCommand(label, scope, children, precondition);
}
/**
* Create a compound command that dynamically computes its child commands, just in
* time when needing to query whether they can be executed. This is different to the
* {@link createDeferredCompoundCommand|more flexible deferred compound} in that the
* children are provided at the time of testing whether the command can be executed,
* delegating that precondition to the provided children in the usual manner of a
* compound command. Thus the children are prepared earlier but are guaranteed not
* to attempt their execution if any of them reports not being executable.
*
* @template <K> the model ID type
*
* @param label a label for the compound command, suitable for presentation in some UI
* @param scope the IDs of models that the compound command will edit
* @param children a function providing the children to add to the compound just in time
* for them to be tested for executability
*
* @see {@link createDeferredCompoundCommand()}
*/
function createStrictDeferredCompoundCommand(label, scope, children) {
return new deferred_compound_command_impl_1.DeferredCompoundCommand(label, scope, children, 'strict');
}
//# sourceMappingURL=deferred-compound-command.js.map