puremvc.patterns.command package

Submodules

puremvc.patterns.command.MacroCommand module

class puremvc.patterns.command.MacroCommand.MacroCommand

Bases: Notifier, ICommand

A base ICommand implementation that executes other ICommand.

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

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

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

See Also

puremvc.core.Controller puremvc.patterns.observer.Notification puremvc.patterns.command.SimpleCommand

add_subcommand(factory: Callable[[], ICommand])

Add a SubCommand.

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

Parameters:

factory (Callable[[], ICommand]) – A callable object that returns an instance of ICommand.

Returns:

None

execute(notification: INotification)

Execute this MacroCommand’s SubCommands.

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

Parameters:

notification (INotification) – The INotification object to be passed to each`SubCommand`.

Returns:

None

initialize_macro_command()

Initialize the MacroCommand.

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

Initialize MyMacroCommand:

def initialize_macro_command(self):
    self.add_subcommand(lambda: FirstCommand())
    self.add_subcommand(lambda: SecondCommand())
    self.add_subcommand(lambda: ThirdCommand())

Note that SubCommand may be any ICommand implementor, MacroCommand or SimpleCommands are both acceptable.

Returns:

None

puremvc.patterns.command.SimpleCommand module

class puremvc.patterns.command.SimpleCommand.SimpleCommand

Bases: Notifier, ICommand

A base ICommand implementation.

Your subclass should override the execute method where your business logic will handle the INotification.

See Also

puremvc.core.Controller puremvc.patterns.observer.Notification puremvc.patterns.command.MacroCommand

execute(notification: INotification)

Fulfill the use-case initiated by the given INotification.

In the Command Pattern, an application use-case typically begins with some user action, which results in an INotification being broadcast, which is handled by business logic in the execute method of an ICommand.

Parameters:

notification (INotification) – The INotification to handle.

Returns:

None

Module contents