Skip to content

Commit 1537272

Browse files
committed
improve route debug
1 parent dc152c1 commit 1537272

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

ember_debug/route-debug.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import classify from 'ember-debug/utils/classify';
55
import dasherize from 'ember-debug/utils/dasherize';
66

77
import Ember from 'ember-debug/utils/ember';
8-
import { later } from 'ember-debug/utils/ember/runloop';
8+
import { _backburner, later } from 'ember-debug/utils/ember/runloop';
9+
import bound from 'ember-debug/utils/bound-method';
910

1011
const { hasOwnProperty } = Object.prototype;
1112

@@ -15,32 +16,29 @@ export default class RouteDebug extends DebugPort {
1516
super.init();
1617
this.__currentURL = this.currentURL;
1718
this.__currentRouter = this.router;
18-
this.observer = setInterval(() => {
19-
if (this.__currentURL !== this.currentURL) {
20-
this.sendCurrentRoute();
21-
this.__currentURL = this.currentURL;
22-
}
23-
if (this.__currentRouter !== this.router) {
24-
this._cachedRouteTree = null;
25-
this.__currentRouter = this.router;
26-
}
27-
}, 150);
19+
_backburner.on('end', bound(this, this.checkForUpdate));
20+
}
21+
22+
checkForUpdate() {
23+
if (this.__currentURL !== this.currentURL) {
24+
this.sendCurrentRoute();
25+
this.__currentURL = this.currentURL;
26+
}
27+
if (this.__currentRouter !== this.router) {
28+
this._cachedRouteTree = null;
29+
this.__currentRouter = this.router;
30+
}
2831
}
2932

3033
willDestroy() {
31-
clearInterval(this.observer);
34+
_backburner.off('end', bound(this, this.checkForUpdate));
3235
super.willDestroy();
3336
}
3437

3538
get router() {
3639
return this.namespace?.owner.lookup('router:main');
3740
}
3841

39-
get applicationController() {
40-
const container = this.namespace?.owner;
41-
return container.lookup('controller:application');
42-
}
43-
4442
get currentPath() {
4543
return this.namespace?.owner.router.currentPath;
4644
}
@@ -113,7 +111,7 @@ export default class RouteDebug extends DebugPort {
113111
}
114112
if (className === fullName) {
115113
// full name returned as is - this resolver does not look for the module.
116-
className = className.replace(new RegExp(`^${type}\:`), '');
114+
className = className.replace(new RegExp(`^${type}:`), '');
117115
} else if (className) {
118116
// Module exists and found
119117
className = className.replace(
@@ -202,7 +200,13 @@ function buildSubTree(routeTree, route) {
202200
controllerClassName = '(unresolved)';
203201
templateName = '(unresolved)';
204202
} else {
205-
controllerName = routeHandler.controllerName || routeHandler.routeName;
203+
const get =
204+
routeHandler.get ||
205+
function (prop) {
206+
return this[prop];
207+
};
208+
controllerName =
209+
get.call(routeHandler, 'controllerName') || routeHandler.routeName;
206210
controllerFactory = owner.factoryFor
207211
? owner.factoryFor(`controller:${controllerName}`)
208212
: owner._lookupFactory(`controller:${controllerName}`);

0 commit comments

Comments
 (0)