Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Update routeDidChange event listener example (adopted-ember-addons#223)
Browse files Browse the repository at this point in the history
The example as it was written induces an endless loop due to a mutual dependency between `EmberRouter` and `RouterService`.
Moving the logic to the application route means the handler is only installed once, and the loop is avoided.
  • Loading branch information
locks authored and poteto committed Mar 23, 2019
1 parent c933c99 commit be5bdbe
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,11 @@ contentSecurityPolicy: {
In order to use the addon, you must first [configure](#configuration) it, then inject it into any Object registered in the container that you wish to track. For example, you can call a `trackPage` event across all your analytics services whenever you transition into a route, like so:

```js
// app/router.js
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
import { get } from '@ember/object';
// app/routes/application.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { scheduleOnce } from '@ember/runloop';
const Router = EmberRouter.extend({
location: config.locationType,
export default Route.extend({
metrics: service(),
router: service(),
Expand All @@ -218,7 +213,6 @@ const Router = EmberRouter.extend({
}
});
export default Router.map(/* ... */);
```

If you wish to only call a single service, just specify it's name as the first argument:
Expand Down Expand Up @@ -284,6 +278,7 @@ import { inject as service } from '@ember/service';
export default Route.extend({
metrics: service(),
afterModel(model) {
const metrics = this.metrics;
const id = model.googleAnalyticsKey;
Expand Down

0 comments on commit be5bdbe

Please sign in to comment.