Skip to content

Commit

Permalink
changes suggested by Jamie White to fix issue with constructor()
Browse files Browse the repository at this point in the history
Ah yeah, this is the ultimate gotcha with controllers — they’re singletons. So that constructor will only be run once for the lifetime of the application.
  • Loading branch information
didoo committed May 25, 2022
1 parent 2ed672e commit ddfc49a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/components/tests/dummy/app/controllers/components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { scheduleOnce } from '@ember/runloop';

function replaceMockStates() {
Expand All @@ -19,8 +20,18 @@ function replaceMockStates() {
});
}
export default class ComponentsController extends Controller {
@service router;

constructor() {
super(...arguments);
this.router.on('routeDidChange', this, 'routeDidChange');
}

routeDidChange() {
scheduleOnce('afterRender', this, replaceMockStates);
}

willDestroy() {
this.router.off('routeDidChange', this, 'routeDidChange');
}
}

0 comments on commit ddfc49a

Please sign in to comment.