Skip to content

Commit

Permalink
improve route debug
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Dec 27, 2023
1 parent dc152c1 commit 1537272
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions ember_debug/route-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import classify from 'ember-debug/utils/classify';
import dasherize from 'ember-debug/utils/dasherize';

import Ember from 'ember-debug/utils/ember';
import { later } from 'ember-debug/utils/ember/runloop';
import { _backburner, later } from 'ember-debug/utils/ember/runloop';
import bound from 'ember-debug/utils/bound-method';

const { hasOwnProperty } = Object.prototype;

Expand All @@ -15,32 +16,29 @@ export default class RouteDebug extends DebugPort {
super.init();
this.__currentURL = this.currentURL;
this.__currentRouter = this.router;
this.observer = setInterval(() => {
if (this.__currentURL !== this.currentURL) {
this.sendCurrentRoute();
this.__currentURL = this.currentURL;
}
if (this.__currentRouter !== this.router) {
this._cachedRouteTree = null;
this.__currentRouter = this.router;
}
}, 150);
_backburner.on('end', bound(this, this.checkForUpdate));
}

checkForUpdate() {
if (this.__currentURL !== this.currentURL) {
this.sendCurrentRoute();
this.__currentURL = this.currentURL;
}
if (this.__currentRouter !== this.router) {
this._cachedRouteTree = null;
this.__currentRouter = this.router;
}
}

willDestroy() {
clearInterval(this.observer);
_backburner.off('end', bound(this, this.checkForUpdate));
super.willDestroy();
}

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

get applicationController() {
const container = this.namespace?.owner;
return container.lookup('controller:application');
}

get currentPath() {
return this.namespace?.owner.router.currentPath;
}
Expand Down Expand Up @@ -113,7 +111,7 @@ export default class RouteDebug extends DebugPort {
}
if (className === fullName) {
// full name returned as is - this resolver does not look for the module.
className = className.replace(new RegExp(`^${type}\:`), '');
className = className.replace(new RegExp(`^${type}:`), '');
} else if (className) {
// Module exists and found
className = className.replace(
Expand Down Expand Up @@ -202,7 +200,13 @@ function buildSubTree(routeTree, route) {
controllerClassName = '(unresolved)';
templateName = '(unresolved)';
} else {
controllerName = routeHandler.controllerName || routeHandler.routeName;
const get =
routeHandler.get ||
function (prop) {
return this[prop];
};
controllerName =
get.call(routeHandler, 'controllerName') || routeHandler.routeName;
controllerFactory = owner.factoryFor
? owner.factoryFor(`controller:${controllerName}`)
: owner._lookupFactory(`controller:${controllerName}`);
Expand Down

0 comments on commit 1537272

Please sign in to comment.