Skip to content

Commit 84629a8

Browse files
committed
ts wip
1 parent 8ac0421 commit 84629a8

File tree

11 files changed

+205
-118
lines changed

11 files changed

+205
-118
lines changed

packages/@ember/debug/ember-inspector-support/debug-port.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import BaseObject from '@ember/debug/ember-inspector-support/utils/base-object';
22

33
export default class extends BaseObject {
44
declare port: any;
5+
declare portNamespace: string;
6+
declare messages: Record<string, Function>;
57
constructor(data: any) {
68
super(data);
79
if (!data) {
@@ -16,7 +18,7 @@ export default class extends BaseObject {
1618
this.setupOrRemovePortListeners('off');
1719
}
1820

19-
sendMessage(name: string, message: any) {
21+
sendMessage(name: string, message?: any) {
2022
if (this.isDestroyed) return;
2123
this.port.send(this.messageName(name), message);
2224
}
@@ -33,12 +35,12 @@ export default class extends BaseObject {
3335
* Setup or tear down port listeners. Call on `init` and `willDestroy`
3436
* @param {String} onOrOff 'on' or 'off' the functions to call i.e. port.on or port.off for adding or removing listeners
3537
*/
36-
setupOrRemovePortListeners(onOrOff) {
38+
setupOrRemovePortListeners(onOrOff: 'on' | 'off') {
3739
let port = this.port;
3840
let messages = this.messages;
3941

4042
for (let name in messages) {
41-
if (messages.hasOwnProperty(name)) {
43+
if (Object.prototype.hasOwnProperty.call(messages, name)) {
4244
port[onOrOff](this.messageName(name), this, messages[name]);
4345
}
4446
}

packages/@ember/debug/ember-inspector-support/general-debug.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint no-empty:0 */
2+
import libraries from '@ember/-internals/metal/lib/libraries';
23
import DebugPort from './debug-port';
34

4-
import Ember from '@ember/debug/ember-inspector-support/utils/ember';
5-
65
/**
76
* Class that handles gathering general information of the inspected app.
87
* ex:
@@ -12,7 +11,26 @@ import Ember from '@ember/debug/ember-inspector-support/utils/ember';
1211
*
1312
* @module ember-debug/general-debug
1413
*/
15-
export default class extends DebugPort {
14+
export default class GeneralDebug extends DebugPort {
15+
portNamespace!: string;
16+
messages!: {
17+
/**
18+
* Called from the inspector to check if the inspected app has been booted.
19+
*/
20+
applicationBooted(): void;
21+
/**
22+
* Called from the inspector to fetch the libraries that are displayed in
23+
* the info tab.
24+
*/
25+
getLibraries(): void;
26+
getEmberCliConfig(): void;
27+
/**
28+
* Called from the inspector to refresh the inspected app.
29+
* Used in case the inspector was opened late and therefore missed capturing
30+
* all info.
31+
*/
32+
refresh(): void;
33+
};
1634
/**
1735
* Fetches the ember-cli configuration info and sets them on
1836
* the `emberCliConfig` property.
@@ -21,8 +39,8 @@ export default class extends DebugPort {
2139
let found = findMetaTag('name', /environment$/);
2240
if (found) {
2341
try {
24-
return JSON.parse(unescape(found.getAttribute('content')));
25-
} catch (e) {}
42+
return JSON.parse(decodeURI(found.getAttribute('content')!));
43+
} catch {}
2644
}
2745
}
2846

@@ -78,21 +96,21 @@ export default class extends DebugPort {
7896
/**
7997
* Called from the inspector to check if the inspected app has been booted.
8098
*/
81-
applicationBooted() {
99+
applicationBooted(this: GeneralDebug) {
82100
this.sendBooted();
83101
},
84102

85103
/**
86104
* Called from the inspector to fetch the libraries that are displayed in
87105
* the info tab.
88106
*/
89-
getLibraries() {
107+
getLibraries(this: GeneralDebug) {
90108
this.sendMessage('libraries', {
91-
libraries: Ember.libraries?._registry,
109+
libraries: libraries?._registry,
92110
});
93111
},
94112

95-
getEmberCliConfig() {
113+
getEmberCliConfig(this: GeneralDebug) {
96114
this.sendMessage('emberCliConfig', {
97115
emberCliConfig: this.emberCliConfig,
98116
});
@@ -117,10 +135,10 @@ export default class extends DebugPort {
117135
* @param {RegExp} regExp
118136
* @return {Element}
119137
*/
120-
function findMetaTag(attribute, regExp = /.*/) {
138+
function findMetaTag(attribute: string, regExp = /.*/) {
121139
let metas = document.querySelectorAll(`meta[${attribute}]`);
122140
for (let i = 0; i < metas.length; i++) {
123-
let match = metas[i].getAttribute(attribute).match(regExp);
141+
let match = metas[i]!.getAttribute(attribute)?.match(regExp);
124142
if (match) {
125143
return metas[i];
126144
}

packages/@ember/debug/ember-inspector-support/libs/promise-assembler.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import RSVP from 'rsvp';
1010
import BaseObject from '@ember/debug/ember-inspector-support/utils/base-object';
1111
import Evented from '../utils/evented';
1212

13+
export type PromiseUpdatedEvent = {
14+
promise: PromiseModel;
15+
};
16+
17+
export type PromiseChainedEvent = {
18+
promise: PromiseModel;
19+
child: PromiseModel;
20+
};
21+
1322
class PromiseAssembler extends Evented.extend(BaseObject) {
1423
// RSVP lib to debug
1524
isStarted = false;
@@ -135,7 +144,7 @@ function fulfill(this: PromiseAssembler, event: any) {
135144
state: 'fulfilled',
136145
value: event.detail,
137146
});
138-
this.trigger('fulfilled', { promise });
147+
this.trigger('fulfilled', { promise } as PromiseUpdatedEvent);
139148
}
140149

141150
function reject(this: PromiseAssembler, event: any) {
@@ -146,7 +155,7 @@ function reject(this: PromiseAssembler, event: any) {
146155
state: 'rejected',
147156
reason: event.detail,
148157
});
149-
this.trigger('rejected', { promise });
158+
this.trigger('rejected', { promise } as PromiseUpdatedEvent);
150159
}
151160

152161
function chain(this: PromiseAssembler, event: any) {
@@ -161,7 +170,7 @@ function chain(this: PromiseAssembler, event: any) {
161170
child.parent = promise;
162171
children.push(child);
163172

164-
this.trigger('chained', { promise, child });
173+
this.trigger('chained', { promise, child } as PromiseChainedEvent);
165174
}
166175

167176
function create(this: PromiseAssembler, event: any) {
@@ -177,5 +186,5 @@ function create(this: PromiseAssembler, event: any) {
177186
if (!promise.state) {
178187
promise.state = 'created';
179188
}
180-
this.trigger('created', { promise });
189+
this.trigger('created', { promise } as PromiseUpdatedEvent);
181190
}

packages/@ember/debug/ember-inspector-support/main.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import ContainerDebug from '@ember/debug/ember-inspector-support/container-debug
1111
import DeprecationDebug from '@ember/debug/ember-inspector-support/deprecation-debug';
1212
import Session from '@ember/debug/ember-inspector-support/services/session';
1313

14-
import { Application, Namespace } from '@ember/debug/ember-inspector-support/utils/ember';
14+
import Application from '@ember/application';
1515
import {
1616
guidFor,
1717
setGuidPrefix,
1818
} from '@ember/debug/ember-inspector-support/utils/ember/object/internals';
1919
import { run } from '@ember/runloop';
2020
import BaseObject from '@ember/debug/ember-inspector-support/utils/base-object';
21+
import Namespace from '@ember/application/namespace';
2122

2223
class EmberDebug extends BaseObject {
2324
/**
@@ -27,6 +28,13 @@ class EmberDebug extends BaseObject {
2728
* @default false
2829
*/
2930
isTesting = false;
31+
private _application: any;
32+
private owner: any;
33+
private started!: boolean;
34+
adapter!: BasicAdapter;
35+
port!: Port;
36+
generalDebug!: GeneralDebug;
37+
objectInspector!: ObjectInspector;
3038

3139
get applicationName() {
3240
return this._application.name || this._application.modulePrefix;
@@ -51,7 +59,7 @@ class EmberDebug extends BaseObject {
5159
Port = Port;
5260
Adapter = BasicAdapter;
5361

54-
start($keepAdapter) {
62+
start($keepAdapter: boolean) {
5563
if (this.started) {
5664
this.reset($keepAdapter);
5765
return;
@@ -85,24 +93,24 @@ class EmberDebug extends BaseObject {
8593
'objectInspector',
8694
'session',
8795
].forEach((prop) => {
88-
let handler = this[prop];
96+
let handler = (this as any)[prop];
8997
if (handler) {
9098
run(handler, 'destroy');
91-
this[prop] = null;
99+
(this as any)[prop] = null;
92100
}
93101
});
94102
}
95103

96-
startModule(prop, Module) {
97-
this[prop] = new Module({ namespace: this });
104+
startModule(prop: string, Module: any) {
105+
(this as any)[prop] = new Module({ namespace: this });
98106
}
99107

100108
willDestroy() {
101109
this.destroyContainer();
102110
super.willDestroy();
103111
}
104112

105-
reset($keepAdapter) {
113+
reset($keepAdapter?: boolean) {
106114
setGuidPrefix(Math.random().toString());
107115
if (!this.isTesting && !this.owner) {
108116
this.owner = getOwner(this._application);
@@ -134,7 +142,7 @@ class EmberDebug extends BaseObject {
134142
});
135143
}
136144

137-
inspect(obj) {
145+
inspect(obj: any) {
138146
this.objectInspector.sendObject(obj);
139147
this.adapter.log('Sent to the Object Inspector');
140148
return obj;
@@ -157,16 +165,18 @@ function getApplication() {
157165
application = namespace;
158166
return false;
159167
}
168+
return;
160169
});
161170
return application;
162171
}
163172

164-
function getOwner(application) {
173+
function getOwner(application: Application) {
165174
if (application.autoboot) {
166175
return application.__deprecatedInstance__;
167176
} else if (application._applicationInstances /* Ember 3.1+ */) {
168177
return [...application._applicationInstances][0];
169178
}
179+
return null;
170180
}
171181

172182
export default new EmberDebug();

0 commit comments

Comments
 (0)