-
Notifications
You must be signed in to change notification settings - Fork 286
/
main.js
183 lines (161 loc) · 4.58 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import BasicAdapter from 'ember-debug/adapters/basic';
import Port from 'ember-debug/port';
import ObjectInspector from 'ember-debug/object-inspector';
import GeneralDebug from 'ember-debug/general-debug';
import RenderDebug from 'ember-debug/render-debug';
import ViewDebug from 'ember-debug/view-debug';
import RouteDebug from 'ember-debug/route-debug';
import DataDebug from 'ember-debug/data-debug';
import PromiseDebug from 'ember-debug/promise-debug';
import ContainerDebug from 'ember-debug/container-debug';
import DeprecationDebug from 'ember-debug/deprecation-debug';
import Session from 'ember-debug/services/session';
const Ember = window.Ember;
const {
Object: EmberObject,
run,
Application,
Namespace,
guidFor,
computed,
} = Ember;
const EmberDebug = EmberObject.extend({
/**
* Set to true during testing.
*
* @type {Boolean}
* @default false
*/
isTesting: false,
/**
* @private
* @property _application
* @type {Application}
*/
_application: null,
owner: null,
started: false,
applicationName: computed
.or('_application.name', '_application.modulePrefix')
.readOnly(),
/**
* We use the application's id instead of the owner's id so that we use the same inspector
* instance for the same application even if it was reset (owner changes on reset).
*
* @property applicationId
* @type {String}
*/
applicationId: computed('_application', 'isTesting', 'owner', function () {
if (!this.isTesting) {
return guidFor(this._application);
}
return guidFor(this.owner);
}),
// Using object shorthand syntax here is somehow having strange side effects.
// eslint-disable-next-line object-shorthand
Port: Port,
Adapter: BasicAdapter,
start($keepAdapter) {
if (this.started) {
this.reset($keepAdapter);
return;
}
if (!this._application && !this.isTesting) {
this.set('_application', getApplication());
}
this.set('started', true);
this.reset();
this.adapter.debug('Ember Inspector Active');
this.adapter.sendMessage({
type: 'inspectorLoaded',
});
},
destroyContainer() {
if (this.generalDebug) {
this.generalDebug.sendReset();
}
[
'dataDebug',
'viewDebug',
'routeDebug',
'generalDebug',
'renderDebug',
'promiseDebug',
'containerDebug',
'deprecationDebug',
'objectInspector',
'session',
].forEach((prop) => {
let handler = this.get(prop);
if (handler) {
run(handler, 'destroy');
this.set(prop, null);
}
});
},
startModule(prop, Module) {
this.set(prop, Module.create({ namespace: this }));
},
willDestroy() {
this.destroyContainer();
this._super(...arguments);
},
reset($keepAdapter) {
if (!this.isTesting && !this.owner) {
this.set('owner', getOwner(this._application));
}
this.destroyContainer();
run(() => {
// Adapters don't have state depending on the application itself.
// They also maintain connections with the inspector which we will
// lose if we destroy.
if (!this.adapter || !$keepAdapter) {
this.startModule('adapter', this.Adapter);
}
if (!this.port || !$keepAdapter) {
this.startModule('port', this.Port);
}
this.startModule('session', Session);
this.startModule('generalDebug', GeneralDebug);
this.startModule('renderDebug', RenderDebug);
this.startModule('objectInspector', ObjectInspector);
this.startModule('routeDebug', RouteDebug);
this.startModule('viewDebug', ViewDebug);
this.startModule('dataDebug', DataDebug);
this.startModule('promiseDebug', PromiseDebug);
this.startModule('containerDebug', ContainerDebug);
this.startModule('deprecationDebug', DeprecationDebug);
this.generalDebug.sendBooted();
});
},
inspect(obj) {
this.objectInspector.sendObject(obj);
this.adapter.log('Sent to the Object Inspector');
return obj;
},
clear() {
this.setProperties({
_application: null,
owner: null,
});
},
}).create();
function getApplication() {
let namespaces = Namespace.NAMESPACES;
let application;
namespaces.forEach((namespace) => {
if (namespace instanceof Application) {
application = namespace;
return false;
}
});
return application;
}
function getOwner(application) {
if (application.autoboot) {
return application.__deprecatedInstance__;
} else if (application._applicationInstances /* Ember 3.1+ */) {
return application._applicationInstances[0];
}
}
export default EmberDebug;