Command.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import DeveloperError from "../Core/DeveloperError.js";
  2. /**
  3. * A Command is a function with an extra <code>canExecute</code> observable property to determine
  4. * whether the command can be executed. When executed, a Command function will check the
  5. * value of <code>canExecute</code> and throw if false.
  6. *
  7. * This type describes an interface and is not intended to be instantiated directly.
  8. * See {@link createCommand} to create a command from a function.
  9. *
  10. * @alias Command
  11. * @constructor
  12. */
  13. function Command() {
  14. /**
  15. * Gets whether this command can currently be executed. This property is observable.
  16. * @type {Boolean}
  17. * @default undefined
  18. */
  19. this.canExecute = undefined;
  20. /**
  21. * Gets an event which is raised before the command executes, the event
  22. * is raised with an object containing two properties: a <code>cancel</code> property,
  23. * which if set to false by the listener will prevent the command from being executed, and
  24. * an <code>args</code> property, which is the array of arguments being passed to the command.
  25. * @type {Event}
  26. * @default undefined
  27. */
  28. this.beforeExecute = undefined;
  29. /**
  30. * Gets an event which is raised after the command executes, the event
  31. * is raised with the return value of the command as its only parameter.
  32. * @type {Event}
  33. * @default undefined
  34. */
  35. this.afterExecute = undefined;
  36. DeveloperError.throwInstantiationError();
  37. }
  38. export default Command;