Fork me on GitHub
Show:

CommandManager

Summary

CommandManager Handles execution and history of commands, and queueing of asynchronous commands.

Example: var cm = new CommandManager(); cm.executeCommand(new CommandOne()); cm.executeCommand(new CommandTwo()); // waits for CommandOne to resolve cm.undo(); // waits for CommandTwo to resolve, the undoes CommandTwo cm.undo(); // waits for CommandTwo to resolve undo, then undoes CommandOne cm.redo(); // waits for CommandOne to resolve undo, then executes CommandOne // etc...

Note that attempts to execute a command that is not available will throw a CommandHistoryError.

To address this, you can catch CommandHistoryErrors:

try { cm.undo(); } catch(e) { if (e instanceof CommandHistoryError) { $('#undoBtn').attr('disabled', disabled') alert('Unable to undo command: ' e.message); } else { // something else went wrong :( throw e; } }

Or, you can check the availability of a command before executing:

if (cm.canUndo()) { cm.undo(); } else { alert('You can\'t undo what hasn\'t been done.'); }

Constructor

aeris.commands.CommandManager

Syntax

aeris.commands.CommandManager

(
  • opt_options
)

Summary

Parameters:

Methods

canRedo

Syntax

canRedo

() Boolean

Summary

Returns:

Boolean:

Whether there is a command to redo.

canUndo

Syntax

canUndo

() Boolean

Summary

Returns:

Boolean:

Whether there is a command to undo.

executeCommand

Syntax

executeCommand

(
  • command
)
promise

Summary

Executes the command

Parameters:

Returns:

promise:

Promise to resolve command execution.

queueAndRun_

Syntax

queueAndRun_

(
  • fn
  • command
)
private

Summary

Add a command action to the PromiseQueue, and make sure the queue is running.

Parameters:

redo

Syntax

redo

() Promise

Summary

Redoes the last executed command.

Returns:

undo

Syntax

undo

() Promise

Summary

Undoes the last executed command.

Returns:

Properties

executed_

Syntax

executed_

Array. private

Summary

A list of executed commands

undone_

Syntax

undone_

Array. private

Summary

A list of undone commands

Events

execute

Syntax

execute

Summary

Event Payload:

redo

Syntax

redo

Summary

Event Payload:

undo

Syntax

undo

Summary

Event Payload: