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
Solved! Go to Solution.
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.
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:
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
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.
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.
John is correct UndoManager doesn't inherit from Evented. We will get this fixed for the next release of the ArcGIS API for JavaScript.