Update released - 2019.02.18.01
Added an Events class. This class is designed to add extra, simple error handling when hooking WME events. All scripts that hook any of the WME events should add in their own error handling, but many do not, to prevent WME updates from breaking multiple scripts - even if there is only an error in one.
If one script breaks after hooking one of the events and the error that is thrown is not caught, the rest of the event handling queue is not executed so other scripts can/will be affected. Changing to use the WW events will prevent other scripts from being affected if there is an issue. Additional error handling should be done in the script, but switching to these events is a quick and easy way to protect your script, and others, in case of an error.
The following events are supported:
Code: Select all
moveend
zoomend
mousemove
changelayer
selectionchanged
change:editingHouseNumbers
afterundoaction
afterclearactions
afteraction
Implement virtually the same as when hooking native events.
Native:
Code: Select all
W.selectionManager.events.register("selectionchanged", null, handler);
W.model.actionManager.events.register("afterundoaction",null, handler);
W.model.actionManager.events.register("afterclearactions",null, handler);
W.model.actionManager.events.register("afteraction",null, handler);
Using WazeWrap:
Code: Select all
WazeWrap.Events.register("selectionchanged", null, handler);
WazeWrap.Events.register("afterundoaction",null, handler);
WazeWrap.Events.register("afterclearactions",null, handler);
WazeWrap.Events.register("afteraction",null, handler);
It is possible to pass an error handling method to the WazeWrap.Events.register() method as well if you want to try and recover from any error that occurs.
Code: Select all
WazeWrap.Events.register("selectionchanged", null, handler, errorHandler);
If no error handling method is passed then the error will be logged to the console, including the method name that threw the error.
To unregister the events, it is again essentially the same as unregistering natively
Code: Select all
WazeWrap.Events.unregister("selectionchanged", null, handler);
WazeWrap.Events.unregister("afterundoaction",null, handler);
WazeWrap.Events.unregister("afterclearactions",null, handler);
WazeWrap.Events.unregister("afteraction",null, handler);
Registering/unregistering for entering/exiting house number edit mode is the only one that is different, but you continue to use the same syntax as registering the other events with WazeWrap.Events
Native:
Code: Select all
W.editingMediator.on('change:editingHouseNumbers', handler);
W.editingMediator.off('change:editingHouseNumbers', handler);
WazeWrap:
Code: Select all
WazeWrap.Events.register("change:editingHouseNumbers", null, handler);
WazeWrap.Events.unregister("change:editingHouseNumbers", null, handler);
Note that when using the WazeWrap.Events.register for these you must pass a null value as the 2nd parameter - this is to keep the usage in line with all of the other register calls, despite the native registrations only taking two parameters.