A quick post about events in the viewer. It's pretty straightforward to listen to events, all you need is knowing the eventId you are looking for. For example the following code illustrates how to set and remove an event listener for the selection changed:
I also went a bit further and created an extension which allows to set and remove events dynamically while outputting arguments in a logger window.
I took the opportunity to try a library called jquery-jsonview, pretty slick to use and handy it lets you dump a json object into a div and nicely formats it.
One limitation I had when stringifying the json to display it in the jsonview is that some of the events are circular structure, hence throwing exception when passed to the built-in JSON.stringify method. No worries once again because no matter what issue you have, there has to be a lib that can help: ended up using circular-json which does as well a pretty good job at handling circular json objects.
Here is the complete code the for the extension and a live version that can be tried from here. Some of the events cannot be tested from the EventWatcher due to timing or other constraints, for example TOOLBAR_CREATED or GEOMETRY_LOADED will be fired before the event extension is even loaded.