Frage

I am trying to implement Backbone.js Undo manager with my existing code. My application is kind of template builder.

Here is console.log of main object. http://screencast.com/t/0JDfCY7l

As you can see it has palette and editor object. I want to register undo, redo with that. Here is my code for undo manager intergation.

var UndoManager = new Backbone.UndoManager;
    UndoManager.register(app.editor,app.palette,DdBuilder); // Pass any number of arguments
    UndoManager.startTracking(); // Start observation after instantiation
    $(".fusion_undo").click(function () {

        alert(UndoManager.isAvailable("undo")); //returns false always
        UndoManager.undo();
    });
    $(".fusion_redo").click(function () {
        UndoManager.redo();
    });

I believe it is simple integration and I am missing some minor details. Any idea what it could be?

War es hilfreich?

Lösung

Do app.editor, app.palette and DbBuilder trigger Backbone-events? The UndoManager adds listeners to the objects that are passed to the register-function. If you haven't extended the supported UndoTypes your UndoManager supports the add, remove, reset and change events and creates undoable actions from these events.

You may want to test whether your objects trigger these events by logging them into the console.

app.editor.on("all", console.log, console);
app.palette.on("all", console.log, console);
DbBuilder.on("all", console.log, console);

If they trigger one of the events and isAvailable("undo") still returns false afterwards then there must be a tougher problem, but try this at first.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top