1- // eslint-disable-next-line ember/no-observers
2- import { action , observer } from '@ember/object' ;
1+ import { action } from '@ember/object' ;
32import Controller from '@ember/controller' ;
43import { inject as service } from '@ember/service' ;
54import { isEmpty } from '@ember/utils' ;
6- import { equal , bool , and , not , filter } from '@ember/object/computed' ;
75import { debounce , next , once } from '@ember/runloop' ;
6+ import { tracked } from '@glimmer/tracking' ;
7+
8+ // eslint-disable-next-line ember/no-observers
9+ import { observes } from '@ember-decorators/object' ;
810
9- export default Controller . extend ( {
10- queryParams : [ 'filter' ] ,
11+ export default class PromiseTreeController extends Controller {
12+ queryParams = [ 'filter' ] ;
1113
12- adapter : service ( ) ,
13- port : service ( ) ,
14+ @ service adapter ;
15+ @ service port ;
1416
15- createdAfter : null ,
17+ @tracked createdAfter = null ;
18+ @tracked filter = 'all' ;
19+ @tracked searchValue = null ;
20+ @tracked effectiveSearch = null ;
1621
1722 // below used to show the "refresh" message
18- isEmpty : equal ( 'model.length' , 0 ) ,
19- wasCleared : bool ( 'createdAfter' ) ,
20- neverCleared : not ( 'wasCleared' ) ,
21- shouldRefresh : and ( 'isEmpty' , 'neverCleared' ) ,
23+ get isEmpty ( ) {
24+ return this . model . length === 0 ;
25+ }
26+ get wasCleared ( ) {
27+ return Boolean ( this . createdAfter ) ;
28+ }
29+ get neverCleared ( ) {
30+ return ! this . wasCleared ;
31+ }
32+ get shouldRefresh ( ) {
33+ return this . isEmpty && this . neverCleared ;
34+ }
2235
2336 // Keep track of promise stack traces.
2437 // It is opt-in due to performance reasons.
25- instrumentWithStack : false ,
38+ @ tracked instrumentWithStack = false ;
2639
27- /* jscs:disable validateIndentation */
28- filtered : filter (
29- 'model.@each.{createdAt,fulfilledBranch,rejectedBranch,pendingBranch,isVisible}' ,
30- function ( item ) {
40+ get filtered ( ) {
41+ return this . model . filter ( ( item ) => {
3142 // exclude cleared promises
3243 if ( this . createdAfter && item . get ( 'createdAt' ) < this . createdAfter ) {
3344 return false ;
@@ -60,27 +71,25 @@ export default Controller.extend({
6071 return item . matches ( search ) ;
6172 }
6273 return true ;
63- } ,
64- ) ,
65- /* jscs:enable validateIndentation */
66-
67- filter : 'all' ,
68- searchValue : null ,
69- effectiveSearch : null ,
74+ } ) ;
75+ }
7076
7177 // eslint-disable-next-line ember/no-observers
72- searchChanged : observer ( 'searchValue' , function ( ) {
78+ @observes ( 'searchValue' )
79+ searchChanged ( ) {
7380 debounce ( this , this . notifyChange , 500 ) ;
74- } ) ,
81+ }
7582
83+ @action
7684 notifyChange ( ) {
77- this . set ( ' effectiveSearch' , this . searchValue ) ;
85+ this . effectiveSearch = this . searchValue ;
7886 next ( ( ) => {
7987 this . notifyPropertyChange ( 'model' ) ;
8088 } ) ;
81- } ,
89+ }
8290
83- toggleExpand : action ( function ( promise ) {
91+ @action
92+ toggleExpand ( promise ) {
8493 let isExpanded = ! promise . get ( 'isExpanded' ) ;
8594 promise . set ( 'isManuallyExpanded' , isExpanded ) ;
8695 promise . recalculateExpanded ( ) ;
@@ -94,37 +103,43 @@ export default Controller.extend({
94103 }
95104 } ) ;
96105 }
97- } ) ,
106+ }
98107
99- tracePromise : action ( function ( promise ) {
108+ @action
109+ tracePromise ( promise ) {
100110 this . port . send ( 'promise:tracePromise' , { promiseId : promise . get ( 'guid' ) } ) ;
101- } ) ,
111+ }
102112
103- inspectObject : action ( function ( ) {
113+ @action
114+ inspectObject ( ) {
104115 this . target . send ( 'inspectObject' , ...arguments ) ;
105- } ) ,
116+ }
106117
107- sendValueToConsole : action ( function ( promise ) {
118+ @action
119+ sendValueToConsole ( promise ) {
108120 this . port . send ( 'promise:sendValueToConsole' , {
109121 promiseId : promise . get ( 'guid' ) ,
110122 } ) ;
111- } ) ,
123+ }
112124
113- setFilter : action ( function ( filter ) {
114- this . set ( 'filter' , filter ) ;
125+ @action
126+ setFilter ( filter ) {
127+ this . filter = filter ;
115128 next ( ( ) => {
116129 this . notifyPropertyChange ( 'filtered' ) ;
117130 } ) ;
118- } ) ,
131+ }
119132
120- updateInstrumentWithStack : action ( function ( bool ) {
133+ @action
134+ updateInstrumentWithStack ( bool ) {
121135 this . port . send ( 'promise:setInstrumentWithStack' , {
122136 instrumentWithStack : bool ,
123137 } ) ;
124- } ) ,
138+ }
125139
126- clear : action ( function ( ) {
127- this . set ( 'createdAfter' , new Date ( ) ) ;
140+ @action
141+ clear ( ) {
142+ this . createdAfter = new Date ( ) ;
128143 once ( this , this . notifyChange ) ;
129- } ) ,
130- } ) ;
144+ }
145+ }
0 commit comments