Skip to content

Commit d7057b5

Browse files
Remove gets and access props directly (#2623)
1 parent fa9e503 commit d7057b5

File tree

7 files changed

+60
-58
lines changed

7 files changed

+60
-58
lines changed

app/controllers/application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export default class ApplicationController extends Controller {
187187
}
188188
});
189189
}
190-
if (this.mixinStack.get('length') > 0) {
190+
if (this.mixinStack.length > 0) {
191191
this.set('mixinDetails', this.mixinStack.at(-1));
192192
} else {
193193
this.set('mixinDetails', null);

app/controllers/promise-tree.js app/controllers/promise-tree.ts

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
11
import { action } from '@ember/object';
22
import Controller from '@ember/controller';
33
import { inject as service } from '@ember/service';
4-
import { isEmpty } from '@ember/utils';
54
import { debounce, next, once } from '@ember/runloop';
65
import { tracked } from '@glimmer/tracking';
76

87
// eslint-disable-next-line ember/no-observers
8+
// @ts-expect-error We should move away from observers.
99
import { 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+
1116
export 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

app/models/promise.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class PromiseModel extends EmberObject {
3939

4040
@tracked branchLabel = '';
4141
@tracked isExpanded = false;
42-
@tracked isManuallyExpanded = undefined;
42+
@tracked isManuallyExpanded?: boolean = undefined;
4343
@tracked parent: PromiseModel | null = null;
4444

4545
get level(): number {

app/routes/application.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable ember/no-controller-access-in-routes */
12
import { inject as service } from '@ember/service';
23
import { action, set } from '@ember/object';
34
import Route from '@ember/routing/route';
@@ -54,7 +55,6 @@ export default class ApplicationRoute extends Route {
5455
NativeArray.apply(details);
5556
details.forEach(arrayize);
5657

57-
// eslint-disable-next-line ember/no-controller-access-in-routes
5858
let controller = this.controller;
5959

6060
if (options.parentObject) {
@@ -63,22 +63,16 @@ export default class ApplicationRoute extends Route {
6363
controller.activateMixinDetails(name, objectId, details, errors);
6464
}
6565

66-
// eslint-disable-next-line ember/no-controller-access-in-routes
6766
this.controller.showInspector();
6867
}
6968

7069
setDeprecationCount(message) {
71-
// eslint-disable-next-line ember/no-controller-access-in-routes
7270
this.controller.set('deprecationCount', message.count);
7371
}
7472

75-
// eslint-enable ember/no-controller-access-in-routes
76-
7773
updateProperty(options) {
78-
if (this.get('controller.mixinDetails.mixins')) {
79-
const detail = this.get('controller.mixinDetails.mixins').at(
80-
options.mixinIndex,
81-
);
74+
if (this.controller.mixinDetails?.mixins) {
75+
const detail = this.controller.mixinDetails.mixins.at(options.mixinIndex);
8276
let property = detail.properties.find((x) => x.name === options.property);
8377
if (!property) return;
8478
set(property, 'value', options.value);
@@ -89,7 +83,8 @@ export default class ApplicationRoute extends Route {
8983
}
9084

9185
updateErrors(options) {
92-
let mixinDetails = this.get('controller.mixinDetails');
86+
let mixinDetails = this.controller.mixinDetails;
87+
9388
if (mixinDetails) {
9489
if (mixinDetails.objectId === options.objectId) {
9590
set(mixinDetails, 'errors', options.errors);
@@ -98,7 +93,6 @@ export default class ApplicationRoute extends Route {
9893
}
9994

10095
droppedObject(message) {
101-
// eslint-disable-next-line ember/no-controller-access-in-routes
10296
this.controller.droppedObject(message.objectId);
10397
}
10498

app/services/port.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export interface Message {
1313
applicationName: string;
1414
frameId?: any;
1515
from: string;
16+
instrumentWithStack?: boolean;
1617
name?: string;
18+
promiseId?: string;
1719
shouldHighlightRender?: boolean;
1820
tabId?: number;
1921
type: string;

tests/ember_debug/object-inspector-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ module('Ember Debug - Object Inspector', function (hooks) {
648648
});
649649
});
650650

651-
assert.strictEqual(inspected.get('name'), 'Alex');
651+
assert.strictEqual(inspected.name, 'Alex');
652652

653653
assert.strictEqual(message.property, 'name');
654654
assert.strictEqual(message.value.inspect, inspect('Alex'));
@@ -674,9 +674,9 @@ module('Ember Debug - Object Inspector', function (hooks) {
674674
});
675675
});
676676

677-
assert.strictEqual(inspected.get('date').getFullYear(), 2015);
678-
assert.strictEqual(inspected.get('date').getMonth(), 0);
679-
assert.strictEqual(inspected.get('date').getDate(), 1);
677+
assert.strictEqual(inspected.date.getFullYear(), 2015);
678+
assert.strictEqual(inspected.date.getMonth(), 0);
679+
assert.strictEqual(inspected.date.getDate(), 1);
680680

681681
assert.strictEqual(message.property, 'date');
682682
assert.strictEqual(message.value.inspect, inspect(newDate));

tests/ember_debug/promise-assembler-test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module('Ember Debug - PromiseAssembler', function (hooks) {
5555
let promise = event.promise;
5656
assert.strictEqual(event.promise, assembler.find(promise['guid']));
5757

58-
assert.strictEqual(assembler.find().get('length'), 1);
58+
assert.strictEqual(assembler.find().length, 1);
5959

6060
assert.strictEqual(promise['guid'], 1);
6161
assert.strictEqual(promise['label'], 'label');
@@ -88,7 +88,7 @@ module('Ember Debug - PromiseAssembler', function (hooks) {
8888
assert.strictEqual(assembler.find(parent['guid']), parent);
8989
assert.strictEqual(assembler.find(child['guid']), child);
9090

91-
assert.strictEqual(assembler.find().get('length'), 2);
91+
assert.strictEqual(assembler.find().length, 2);
9292

9393
assert.strictEqual(parent['guid'], 1);
9494
assert.strictEqual(parent['label'], 'label');
@@ -147,7 +147,7 @@ module('Ember Debug - PromiseAssembler', function (hooks) {
147147
assert.strictEqual(assembler.find(parent['guid']), parent);
148148
assert.strictEqual(assembler.find(child['guid']), child);
149149

150-
assert.strictEqual(assembler.find().get('length'), 2);
150+
assert.strictEqual(assembler.find().length, 2);
151151

152152
assert.strictEqual(parent['guid'], 1);
153153
assert.strictEqual(parent['label'], 'label');
@@ -230,7 +230,7 @@ module('Ember Debug - PromiseAssembler', function (hooks) {
230230
assert.strictEqual(promise['state'], 'rejected');
231231
assert.strictEqual(promise['reason'], 'reason');
232232
assert.strictEqual(promise['settledAt'], date);
233-
assert.strictEqual(assembler.find().get('length'), 1);
233+
assert.strictEqual(assembler.find().length, 1);
234234
});
235235

236236
test('#stop', function (assert) {
@@ -239,15 +239,15 @@ module('Ember Debug - PromiseAssembler', function (hooks) {
239239
fakeRSVP.trigger('created', {
240240
guid: 1,
241241
});
242-
assert.strictEqual(assembler.find().get('length'), 1);
242+
assert.strictEqual(assembler.find().length, 1);
243243

244244
run(assembler, 'stop');
245245

246-
assert.strictEqual(assembler.find().get('length'), 0);
246+
assert.strictEqual(assembler.find().length, 0);
247247
assembler.on('created', function () {
248248
assert.ok(false);
249249
});
250250
fakeRSVP.trigger('created', { guid: 1 });
251-
assert.strictEqual(assembler.find().get('length'), 0);
251+
assert.strictEqual(assembler.find().length, 0);
252252
});
253253
});

0 commit comments

Comments
 (0)