tildeio/router.js — pull request #89 by ef4 (2014-04-08 20:07:23+00:00)
Title: willLeave and willChangeContext events

This supercedes https://github.com/emberjs/ember.js/pull/4233

My intention is to expose a public API that's more fine-grained than `willTransition`. The problem with `willTransition` is that it fires on your route regardless of whether your route is actually going to be affected by the transition. The user is left crawling through private state on the transition object to figure out whether their route is really going away or changing context.

This change creates two new events: `willLeave` and `willChangeContext`. `willLeave` fires on routes that will no longer be active after the transition. `willChangeContext` fires on routes that will still be active but will re-resolve their models. Both of these hooks act like `willTransition` is the sense that they give you an opportunity to abort the transition before it happens. Common use cases include animating things away or prompting to user to deal with unsaved changes.

If this PR is merged, I'll make a (documentation-only) PR against ember itself. As far as I can tell, no code changes will be necessary there.

I left `willTransition` alone, so this should be backward compatible with stable Ember APIs.