A base Command implementation that executes other Commands.

A MacroCommand maintains a list of Command Class references called SubCommands.

When execute is called, the MacroCommand instantiates and calls execute on each of its SubCommands turn. Each SubCommand will be passed a reference to the original Notification that was passed to the MacroCommand's execute method.

Unlike SimpleCommand, your subclass should not override execute, but instead, should override the initializeMacroCommand method, calling addSubCommand once for each SubCommand to be executed.

Hierarchy (view full)

Constructors

  • Constructor.

    You should not need to define a constructor, instead, override the initializeMacroCommand method.

    If your subclass does define a constructor, be sure to call super().

    Returns MacroCommand

Properties

facade: IFacade = ...

Return the Singleton Facade instance

The facade instance.

Methods

  • Add a SubCommand.

    The SubCommands will be called in First In/First Out (FIFO) order.

    Parameters

    • factory: (() => ICommand)

      A factory function that creates an instance of ICommand. This function will be used to generate the sub-command.

    Returns void

  • Execute this MacroCommand's SubCommands.

    The SubCommands will be called in First In/First Out (FIFO) order.

    Parameters

    • notification: INotification

      The notification containing the data or command details to be processed.

    Returns void

  • Initialize the MacroCommand.

    In your subclass, override this method to initialize the MacroCommand's SubCommand list with Command class references like this:

    // Initialize MyMacroCommand
    initializeMacroCommand() {
    this.addSubCommand(() => new app.FirstCommand());
    this.addSubCommand(() => new app.SecondCommand());
    this.addSubCommand(() => new app.ThirdCommand());
    }

    Note that SubCommands may be any Command implementor, MacroCommands or SimpleCommands are both acceptable.

    Returns void

  • Create and send an Notification.

    Keeps us from having to construct new Notification instances in our implementation code.

    Parameters

    • notificationName: string

      The name of the notification to be sent.

    • Optionalbody: any

      Optional data to be included with the notification.

    • Optionaltype: string

      Optional type of the notification.

    Returns void