UndoManager change event listener

4250
4
Jump to solution
08-12-2014 03:19 PM
MattCooper
Occasional Contributor

I'm not having any luck setting up the event listener for the UndoManager unless I use the "connect" style instead of the "on" style.

    

var undoManager = new UndoManager();

undoManager.on("change", checkUndoRedoState); //this throws an error

connect.connect(undoManager, "onChange", checkUndoRedoState); //this works fine

Any ideas what I'm missing?

Thanks,Matt

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

My guess is that the UndoManager class does not inherit from 'Evented' (see dojo/Evented).  Until that happens you'll have to use the 'connect' pattern which, as you mention above, works just fine.

View solution in original post

4 Replies
OwenEarley
Regular Contributor

I noticed that the ESRI sample for the Undo Manager uses the old connect style:

Graphics with undo redo | ArcGIS API for JavaScript

After changing this sample to use the 'on' style event I also get an error. Adding some console.log lines shows the following:

undomanager.png

The 'on' function of the undo manager is undefined. Other 'on' functions are fine (such as the map.on above).

Interestingly, using the alternate dojo.on style gives another message, for example the following results:

        on(map, "load", function () {

            console.log("on-map-load");

        });

        // console: on-map-load

        on(undoManager, "change", checkUndoRedoState);

        // Uncaught Error: Target must be an event emitter

Not sure if this is a bug.

Owen

Spatial XP

JohnGrayson
Esri Regular Contributor

My guess is that the UndoManager class does not inherit from 'Evented' (see dojo/Evented).  Until that happens you'll have to use the 'connect' pattern which, as you mention above, works just fine.

View solution in original post

MattCooper
Occasional Contributor

Thanks for the responses.  I was just thinking I might have been missing something obvious since the docs seem to imply that the class supports the "on" style, but I think you're all right.  I'll just stick with the "connect" pattern for now.

0 Kudos
KellyHutchins
Esri Frequent Contributor

John is correct UndoManager doesn't inherit from Evented. We will get this fixed for the next release of the ArcGIS API for JavaScript.