derickbailey/backbone.memento — Issue #5: support named states, and only storing / restoring certain attributes
Author: derickbailey
Created: 2011-10-08 18:24:52+00:00
State: open

add support for named states, or named stacks of states. from Dan Switzer via the Backbone mailing list:

-------------------------

For me, I think the best way for it to work would be this:

store([cid]) - always returns the cid. If no cid is provided as an
argument, one is created.

restore([cid]) - If no cid is supplied, restores previous state. If a
cid is specified, rolls all the back to the named state.

This would allow you to do:

1) Rollback to any given point and time:
transactionId = this.store(); // this returns transactionId
this.restore(transactionId);

2) Rollback to a specific point in time:
this.store("init");
this.restore("init");

NOTE: It might be handy to be able to have multiple transaction points
with the same name, that way you could easily create "undo" points. So,
calling this.restore("undo") would rollback to the first named "undo"
transaction. Calling this.restore("undo") would rollback to the next,
etc. That might be pretty powerful.

3) Rollback just like you do now:
this.store();
this.restore();

The reason named transaction are important for me, is I have some code
currently in production that can make a series of triggered model
changes. This code currently isn't using backbone and one of the
problems I'm facing is a proper "undo". The problem is the sequence of
triggered events might make multiple "undo" points, so I need to be able
to roll back to the correct undo point.