emberjs/ember.js — pull request #3689 by tim-evans (2013-11-04 05:00:58+00:00)
Title: Add document.title integration to Ember

This is a copy over of #2757 with a few modifications. I've added feature flagging and layering to expose the ability to override how the document.title is created.

To enable this feature set the flag `"ember-document-title"` to `true`.

A typical example for an application would be the following:

```javascript
App = Ember.Application.create();

App.Router = Ember.Router.extend({
titleDivider: '>',
titleSpecificityIncreases: true
});

App.Router.map(function () {
this.resource('users');
this.resource('user', { path: '/users/:user_id' });
});

App.ApplicationRoute = Ember.Route.extend({
title: "MyApp"
});

App.UsersRoute.extend({
title: "Users"
});

App.UserRoute.extend({
title: Ember.computed.oneWay('controller.name')
});
```

This structure will update the title of the document to `MyApp` when the app loads; `MyApp | Users` after transitioning to /users; and `MyApp | Finn the Human` upon loading the user for Finn the Human.

If you would like to override how the title property is displayed, simply override the `title` property on `App.Router`. When the `title` property becomes invalidated, the document title updates. That is the only contract you must satisfy. To get the tokens that the title is composed of, look at the `titleTokens` property. If overriding the `title`, you should make the `title` dependent on title tokens.

Side question:
The tests are passing, but the observers aren't getting removed. This needs a patch in tildeio/router in setupContexts to call willTransition to ensure that observers are getting torn down. I'm not sure, but are the observers getting removed upon transitioning away from a route, or do I have to remove them myself?