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:
-
opt_options
Object=-
queueManager
PromiseQueue=
-
Item Index
Methods
Methods
executeCommand
Syntax
Summary
Executes the command
Parameters:
-
command
AbstractCommand
Returns:
Promise to resolve command execution.
queueAndRun_
Syntax
queueAndRun_
-
fn
-
command
Summary
Add a command action to the PromiseQueue, and make sure the queue is running.
Parameters:
-
fn
function(): PromiseThe action to add to the queue.
-
command
AbstractCommandThe command to which the action belongs.
Properties
executed_
Syntax
executed_
Array.Summary
A list of executed commands
undone_
Syntax
undone_
Array.Summary
A list of undone commands