montagejs/montage — pull request #1095 by mczepiel (2013-01-12 23:38:32+00:00)
Title: Make UndoManager asynchronous-operation friendly

The forward march of Promises continues unabated. While adding undo/redo
operations continues to be synchronous, the population of these promises
can now be deferred until later.

For example, when any user interaction concludes, a promise for further
information on how to undo that operation is added to the undo stack.
Again, intent is always considered synchronous even if the
information for undoing that operation is will be known later.

At this point a user can undo this operation even without knowing how
that will happen.

While the UndoManager now only accepts promises, even synchronous
user operations will need to build a promise. In this scenario the
promise will likely be resolved in place, with fulfillment handled in
the nextTick.

From here on the story is the same for synchronous or asynchronous
user operations; invoked undo and redo operations are placed in a queue
and performed in a FIFO manner as soon as possible.

Currently, when asking to undo an operation that has not finished
the operation must be allowed to finish. That is, there's no stopping
the train once leaves until it reaches its destination.

The adoption of promises should make for some approachable
implementation of grouping undo operations.