11import { action } from '@ember/object' ;
22import Controller from '@ember/controller' ;
33import { inject as service } from '@ember/service' ;
4- import { isEmpty } from '@ember/utils' ;
54import { debounce , next , once } from '@ember/runloop' ;
65import { tracked } from '@glimmer/tracking' ;
76
87// eslint-disable-next-line ember/no-observers
8+ // @ts -expect-error We should move away from observers.
99import { observes } from '@ember-decorators/object' ;
1010
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+
1116export default class PromiseTreeController extends Controller {
1217 queryParams = [ 'filter' ] ;
1318
14- @service adapter ;
15- @service port ;
19+ declare model : Array < PromiseModel > ;
20+
21+ @service declare adapter : WebExtension ;
22+ @service declare port : PortService ;
1623
17- @tracked createdAfter = null ;
24+ @tracked createdAfter : Date | null = null ;
25+ @tracked effectiveSearch : string | null = null ;
1826 @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 ;
2131
2232 // below used to show the "refresh" message
2333 get isEmpty ( ) {
2434 return this . model . length === 0 ;
2535 }
26- get wasCleared ( ) {
27- return Boolean ( this . createdAfter ) ;
28- }
36+
2937 get neverCleared ( ) {
3038 return ! this . wasCleared ;
3139 }
40+
3241 get shouldRefresh ( ) {
3342 return this . isEmpty && this . neverCleared ;
3443 }
3544
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+ }
3948
4049 get filtered ( ) {
4150 return this . model . filter ( ( item ) => {
4251 // exclude cleared promises
43- if ( this . createdAfter && item . get ( ' createdAt' ) < this . createdAfter ) {
52+ if ( this . createdAfter && item . createdAt < this . createdAfter ) {
4453 return false ;
4554 }
4655
47- if ( ! item . get ( ' isVisible' ) ) {
56+ if ( ! item . isVisible ) {
4857 return false ;
4958 }
5059
@@ -53,11 +62,11 @@ export default class PromiseTreeController extends Controller {
5362 // then they pass
5463 let include = true ;
5564 if ( this . filter === 'pending' ) {
56- include = item . get ( ' pendingBranch' ) ;
65+ include = item . pendingBranch ;
5766 } else if ( this . filter === 'rejected' ) {
58- include = item . get ( ' rejectedBranch' ) ;
67+ include = item . rejectedBranch ;
5968 } else if ( this . filter === 'fulfilled' ) {
60- include = item . get ( ' fulfilledBranch' ) ;
69+ include = item . fulfilledBranch ;
6170 }
6271 if ( ! include ) {
6372 return false ;
@@ -67,7 +76,7 @@ export default class PromiseTreeController extends Controller {
6776 // If they or at least one of their children
6877 // match the search, then include them
6978 let search = this . effectiveSearch ;
70- if ( ! isEmpty ( search ) ) {
79+ if ( ! isNullish ( search ) ) {
7180 return item . matches ( search ) ;
7281 }
7382 return true ;
@@ -89,51 +98,48 @@ export default class PromiseTreeController extends Controller {
8998 }
9099
91100 @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 ;
95104 promise . recalculateExpanded ( ) ;
96105 let children = promise . _allChildren ( ) ;
97106 if ( isExpanded ) {
98107 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 ;
102110 child . recalculateExpanded ( ) ;
103111 }
104112 } ) ;
105113 }
106114 }
107115
108116 @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 } ) ;
111119 }
112120
113121 @action
114122 inspectObject ( ) {
123+ // @ts -expect-error TODO: figure this out later
115124 this . target . send ( 'inspectObject' , ...arguments ) ;
116125 }
117126
118127 @action
119- sendValueToConsole ( promise ) {
128+ sendValueToConsole ( promise : PromiseModel ) {
120129 this . port . send ( 'promise:sendValueToConsole' , {
121- promiseId : promise . get ( ' guid' ) ,
130+ promiseId : promise . guid ,
122131 } ) ;
123132 }
124133
125134 @action
126- setFilter ( filter ) {
135+ setFilter ( filter : string ) {
127136 this . filter = filter ;
128- next ( ( ) => {
129- this . notifyPropertyChange ( 'filtered' ) ;
130- } ) ;
131137 }
132138
133139 @action
134- updateInstrumentWithStack ( bool ) {
140+ updateInstrumentWithStack ( instrumentWithStack : boolean ) {
135141 this . port . send ( 'promise:setInstrumentWithStack' , {
136- instrumentWithStack : bool ,
142+ instrumentWithStack,
137143 } ) ;
138144 }
139145
0 commit comments