An Undo Manager for Javascript Applications

We just added undo and redo functionality to Divshot and along with it we're releasing our first open source library, the Buffered Undo Manager. This library provides a simple undo manager for storing a stack of states for your Javscript application. So where does the "Buffered" part come in?

One of Divshot's features are real-time updates. You change a letter, you see the results immediately. But when it comes to undos it can be frustrating to have to undo each individual keypress. The Buffered Undo Manager provides a buffered time window during which no additional undo states will be created. This way groups of changes that occur within a very short time will all be lumped into a single "undo" making it easier on the user and easier on stack memory consumption. Sound interesting? Check out the demo.

How do you use it? Well, first you'll need jQuery and Underscore included in your application. Once you have those, it's simple:

var manager = new BufferedUndoManager();

manager.state; // "second"
manager.state; // "first"
manager.state; // "second"

// What if we have frequent updates, such as a keyup?
manager.state; // "third"
manager.state; // "second"

// Pass the force option to trigger an update regardless of
// speed.
manager.update("t", {force: true});
manager.state; // "t"

For more information, you can see the GitHub repo or Docco documentatio n. We plan to continue releasing open source as we build out Divshot so stay tuned to this blog for further libaries and announcements as we continue forward!