Switch to using observer from event listeners.

This lets us to track when page is unloaded.
Implement simple `when` helper for events.
Add interface to get a promise for next state.
Add simple test for dev/panel.