@@ -5,7 +5,8 @@ import classify from 'ember-debug/utils/classify';
5
5
import dasherize from 'ember-debug/utils/dasherize' ;
6
6
7
7
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' ;
9
10
10
11
const { hasOwnProperty } = Object . prototype ;
11
12
@@ -15,32 +16,35 @@ export default class RouteDebug extends DebugPort {
15
16
super . init ( ) ;
16
17
this . __currentURL = this . currentURL ;
17
18
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
+ }
28
31
}
29
32
30
33
willDestroy ( ) {
31
- clearInterval ( this . observer ) ;
34
+ _backburner . off ( 'end' , bound ( this , this . checkForUpdate ) ) ;
32
35
super . willDestroy ( ) ;
33
36
}
34
37
35
38
get router ( ) {
39
+ if (
40
+ this . namespace ?. owner . isDestroyed ||
41
+ this . namespace ?. owner . isDestroying
42
+ ) {
43
+ return null ;
44
+ }
36
45
return this . namespace ?. owner . lookup ( 'router:main' ) ;
37
46
}
38
47
39
- get applicationController ( ) {
40
- const container = this . namespace ?. owner ;
41
- return container . lookup ( 'controller:application' ) ;
42
- }
43
-
44
48
get currentPath ( ) {
45
49
return this . namespace ?. owner . router . currentPath ;
46
50
}
@@ -73,7 +77,13 @@ export default class RouteDebug extends DebugPort {
73
77
}
74
78
75
79
get routeTree ( ) {
76
- if ( ! this . _cachedRouteTree ) {
80
+ if (
81
+ this . namespace ?. owner . isDestroyed ||
82
+ this . namespace ?. owner . isDestroying
83
+ ) {
84
+ return null ;
85
+ }
86
+ if ( ! this . _cachedRouteTree && this . router ) {
77
87
const router = this . router ;
78
88
const routerLib = router . _routerMicrolib || router . router ;
79
89
let routeNames = routerLib . recognizer . names ;
@@ -91,8 +101,14 @@ export default class RouteDebug extends DebugPort {
91
101
}
92
102
93
103
sendTree ( ) {
94
- const routeTree = this . routeTree ;
95
- this . sendMessage ( 'routeTree' , { tree : routeTree } ) ;
104
+ let routeTree ;
105
+ let error ;
106
+ try {
107
+ routeTree = this . routeTree ;
108
+ } catch ( e ) {
109
+ error = e . message ;
110
+ }
111
+ this . sendMessage ( 'routeTree' , { tree : routeTree , error } ) ;
96
112
}
97
113
98
114
getClassName ( name , type ) {
@@ -113,7 +129,7 @@ export default class RouteDebug extends DebugPort {
113
129
}
114
130
if ( className === fullName ) {
115
131
// full name returned as is - this resolver does not look for the module.
116
- className = className . replace ( new RegExp ( `^${ type } \ :` ) , '' ) ;
132
+ className = className . replace ( new RegExp ( `^${ type } :` ) , '' ) ;
117
133
} else if ( className ) {
118
134
// Module exists and found
119
135
className = className . replace (
@@ -202,7 +218,13 @@ function buildSubTree(routeTree, route) {
202
218
controllerClassName = '(unresolved)' ;
203
219
templateName = '(unresolved)' ;
204
220
} else {
205
- controllerName = routeHandler . controllerName || routeHandler . routeName ;
221
+ const get =
222
+ routeHandler . get ||
223
+ function ( prop ) {
224
+ return this [ prop ] ;
225
+ } ;
226
+ controllerName =
227
+ get . call ( routeHandler , 'controllerName' ) || routeHandler . routeName ;
206
228
controllerFactory = owner . factoryFor
207
229
? owner . factoryFor ( `controller:${ controllerName } ` )
208
230
: owner . _lookupFactory ( `controller:${ controllerName } ` ) ;
0 commit comments