1
1
import { action } from '@ember/object' ;
2
2
import Controller from '@ember/controller' ;
3
3
import { inject as service } from '@ember/service' ;
4
- import { isEmpty } from '@ember/utils' ;
5
4
import { debounce , next , once } from '@ember/runloop' ;
6
5
import { tracked } from '@glimmer/tracking' ;
7
6
8
7
// eslint-disable-next-line ember/no-observers
8
+ // @ts -expect-error We should move away from observers.
9
9
import { observes } from '@ember-decorators/object' ;
10
10
11
+ import type PortService from '../services/port' ;
12
+ import type PromiseModel from '../models/promise' ;
13
+ import type WebExtension from '../services/adapters/web-extension' ;
14
+ import { isNullish } from 'ember-inspector/utils/nullish' ;
15
+
11
16
export default class PromiseTreeController extends Controller {
12
17
queryParams = [ 'filter' ] ;
13
18
14
- @service adapter ;
15
- @service port ;
19
+ declare model : Array < PromiseModel > ;
20
+
21
+ @service declare adapter : WebExtension ;
22
+ @service declare port : PortService ;
16
23
17
- @tracked createdAfter = null ;
24
+ @tracked createdAfter : Date | null = null ;
25
+ @tracked effectiveSearch : string | null = null ;
18
26
@tracked filter = 'all' ;
19
- @tracked searchValue = null ;
20
- @tracked effectiveSearch = null ;
27
+ // Keep track of promise stack traces.
28
+ // It is opt-in due to performance reasons.
29
+ @tracked instrumentWithStack = false ;
30
+ @tracked searchValue : string | null = null ;
21
31
22
32
// below used to show the "refresh" message
23
33
get isEmpty ( ) {
24
34
return this . model . length === 0 ;
25
35
}
26
- get wasCleared ( ) {
27
- return Boolean ( this . createdAfter ) ;
28
- }
36
+
29
37
get neverCleared ( ) {
30
38
return ! this . wasCleared ;
31
39
}
40
+
32
41
get shouldRefresh ( ) {
33
42
return this . isEmpty && this . neverCleared ;
34
43
}
35
44
36
- // Keep track of promise stack traces.
37
- // It is opt-in due to performance reasons.
38
- @ tracked instrumentWithStack = false ;
45
+ get wasCleared ( ) {
46
+ return Boolean ( this . createdAfter ) ;
47
+ }
39
48
40
49
get filtered ( ) {
41
50
return this . model . filter ( ( item ) => {
42
51
// exclude cleared promises
43
- if ( this . createdAfter && item . get ( ' createdAt' ) < this . createdAfter ) {
52
+ if ( this . createdAfter && item . createdAt < this . createdAfter ) {
44
53
return false ;
45
54
}
46
55
47
- if ( ! item . get ( ' isVisible' ) ) {
56
+ if ( ! item . isVisible ) {
48
57
return false ;
49
58
}
50
59
@@ -53,11 +62,11 @@ export default class PromiseTreeController extends Controller {
53
62
// then they pass
54
63
let include = true ;
55
64
if ( this . filter === 'pending' ) {
56
- include = item . get ( ' pendingBranch' ) ;
65
+ include = item . pendingBranch ;
57
66
} else if ( this . filter === 'rejected' ) {
58
- include = item . get ( ' rejectedBranch' ) ;
67
+ include = item . rejectedBranch ;
59
68
} else if ( this . filter === 'fulfilled' ) {
60
- include = item . get ( ' fulfilledBranch' ) ;
69
+ include = item . fulfilledBranch ;
61
70
}
62
71
if ( ! include ) {
63
72
return false ;
@@ -67,7 +76,7 @@ export default class PromiseTreeController extends Controller {
67
76
// If they or at least one of their children
68
77
// match the search, then include them
69
78
let search = this . effectiveSearch ;
70
- if ( ! isEmpty ( search ) ) {
79
+ if ( ! isNullish ( search ) ) {
71
80
return item . matches ( search ) ;
72
81
}
73
82
return true ;
@@ -89,51 +98,48 @@ export default class PromiseTreeController extends Controller {
89
98
}
90
99
91
100
@action
92
- toggleExpand ( promise ) {
93
- let isExpanded = ! promise . get ( ' isExpanded' ) ;
94
- promise . set ( ' isManuallyExpanded' , isExpanded ) ;
101
+ toggleExpand ( promise : PromiseModel ) {
102
+ let isExpanded = ! promise . isExpanded ;
103
+ promise . isManuallyExpanded = isExpanded ;
95
104
promise . recalculateExpanded ( ) ;
96
105
let children = promise . _allChildren ( ) ;
97
106
if ( isExpanded ) {
98
107
children . forEach ( ( child ) => {
99
- let isManuallyExpanded = child . get ( 'isManuallyExpanded' ) ;
100
- if ( isManuallyExpanded === undefined ) {
101
- child . set ( 'isManuallyExpanded' , isExpanded ) ;
108
+ if ( isNullish ( child . isManuallyExpanded ) ) {
109
+ child . isManuallyExpanded = isExpanded ;
102
110
child . recalculateExpanded ( ) ;
103
111
}
104
112
} ) ;
105
113
}
106
114
}
107
115
108
116
@action
109
- tracePromise ( promise ) {
110
- this . port . send ( 'promise:tracePromise' , { promiseId : promise . get ( ' guid' ) } ) ;
117
+ tracePromise ( promise : PromiseModel ) {
118
+ this . port . send ( 'promise:tracePromise' , { promiseId : promise . guid } ) ;
111
119
}
112
120
113
121
@action
114
122
inspectObject ( ) {
123
+ // @ts -expect-error TODO: figure this out later
115
124
this . target . send ( 'inspectObject' , ...arguments ) ;
116
125
}
117
126
118
127
@action
119
- sendValueToConsole ( promise ) {
128
+ sendValueToConsole ( promise : PromiseModel ) {
120
129
this . port . send ( 'promise:sendValueToConsole' , {
121
- promiseId : promise . get ( ' guid' ) ,
130
+ promiseId : promise . guid ,
122
131
} ) ;
123
132
}
124
133
125
134
@action
126
- setFilter ( filter ) {
135
+ setFilter ( filter : string ) {
127
136
this . filter = filter ;
128
- next ( ( ) => {
129
- this . notifyPropertyChange ( 'filtered' ) ;
130
- } ) ;
131
137
}
132
138
133
139
@action
134
- updateInstrumentWithStack ( bool ) {
140
+ updateInstrumentWithStack ( instrumentWithStack : boolean ) {
135
141
this . port . send ( 'promise:setInstrumentWithStack' , {
136
- instrumentWithStack : bool ,
142
+ instrumentWithStack,
137
143
} ) ;
138
144
}
139
145
0 commit comments