1
1
/* eslint no-console: 0 */
2
2
import { onReady } from 'ember-debug/utils/on-ready' ;
3
+ import BaseObject from '../utils/base-object' ;
3
4
4
- import { A } from 'ember-debug/utils/ember/array' ;
5
- import EmberObject , { computed } from 'ember-debug/utils/ember/object' ;
6
- import { Promise , resolve } from 'ember-debug/utils/rsvp' ;
7
-
8
- export default EmberObject . extend ( {
5
+ export default class BasicAdapter extends BaseObject {
9
6
init ( ) {
10
- resolve ( this . connect ( ) , 'ember-inspector' ) . then (
11
- ( ) => {
12
- this . onConnectionReady ( ) ;
13
- } ,
14
- null ,
15
- 'ember-inspector'
16
- ) ;
7
+ Promise . resolve ( this . connect ( ) ) . then ( ( ) => {
8
+ this . onConnectionReady ( ) ;
9
+ } , null ) ;
17
10
18
11
this . _messageCallbacks = [ ] ;
19
- } ,
12
+ }
20
13
21
14
/**
22
15
* Uses the current build's config module to determine
@@ -25,17 +18,21 @@ export default EmberObject.extend({
25
18
* @property environment
26
19
* @type {String }
27
20
*/
28
- environment : computed ( function ( ) {
29
- return requireModule ( 'ember-debug/config' ) [ 'default' ] . environment ;
30
- } ) ,
21
+ get environment ( ) {
22
+ if ( ! this . __environment ) {
23
+ this . __environment =
24
+ requireModule ( 'ember-debug/config' ) [ 'default' ] . environment ;
25
+ }
26
+ return this . __environment ;
27
+ }
31
28
32
29
debug ( ) {
33
30
return console . debug ( ...arguments ) ;
34
- } ,
31
+ }
35
32
36
33
log ( ) {
37
34
return console . log ( ...arguments ) ;
38
- } ,
35
+ }
39
36
40
37
/**
41
38
* A wrapper for `console.warn`.
@@ -44,14 +41,14 @@ export default EmberObject.extend({
44
41
*/
45
42
warn ( ) {
46
43
return console . warn ( ...arguments ) ;
47
- } ,
44
+ }
48
45
49
46
/**
50
47
Used to send messages to EmberExtension
51
48
52
49
@param {Object } type the message to the send
53
50
*/
54
- sendMessage ( /* options */ ) { } ,
51
+ sendMessage ( /* options */ ) { }
55
52
56
53
/**
57
54
Register functions to be called
@@ -61,7 +58,7 @@ export default EmberObject.extend({
61
58
*/
62
59
onMessageReceived ( callback ) {
63
60
this . _messageCallbacks . push ( callback ) ;
64
- } ,
61
+ }
65
62
66
63
/**
67
64
Inspect a specific DOM node. This usually
@@ -74,13 +71,13 @@ export default EmberObject.extend({
74
71
75
72
@param {Node } node
76
73
*/
77
- inspectNode ( /* node */ ) { } ,
74
+ inspectNode ( /* node */ ) { }
78
75
79
76
_messageReceived ( message ) {
80
77
this . _messageCallbacks . forEach ( ( callback ) => {
81
78
callback ( message ) ;
82
79
} ) ;
83
- } ,
80
+ }
84
81
85
82
/**
86
83
* Handle an error caused by EmberDebug.
@@ -109,7 +106,7 @@ export default EmberObject.extend({
109
106
this . warn ( 'EmberDebug has errored:' ) ;
110
107
throw error ;
111
108
}
112
- } ,
109
+ }
113
110
114
111
/**
115
112
@@ -131,26 +128,24 @@ export default EmberObject.extend({
131
128
}
132
129
} , 10 ) ;
133
130
} ) ;
134
- } , 'ember-inspector' ) ;
135
- } ,
131
+ } ) ;
132
+ }
136
133
137
134
willDestroy ( ) {
138
- this . _super ( ) ;
135
+ super . willDestroy ( ) ;
139
136
clearInterval ( this . interval ) ;
140
- } ,
137
+ }
141
138
142
- _isReady : false ,
143
- _pendingMessages : computed ( function ( ) {
144
- return A ( ) ;
145
- } ) ,
139
+ _isReady = false ;
140
+ _pendingMessages = [ ] ;
146
141
147
142
send ( options ) {
148
143
if ( this . _isReady ) {
149
144
this . sendMessage ( ...arguments ) ;
150
145
} else {
151
146
this . _pendingMessages . push ( options ) ;
152
147
}
153
- } ,
148
+ }
154
149
155
150
/**
156
151
Called when the connection is set up.
@@ -160,7 +155,7 @@ export default EmberObject.extend({
160
155
// Flush pending messages
161
156
const messages = this . _pendingMessages ;
162
157
messages . forEach ( ( options ) => this . sendMessage ( options ) ) ;
163
- messages . clear ( ) ;
158
+ messages . length = 0 ;
164
159
this . _isReady = true ;
165
- } ,
166
- } ) ;
160
+ }
161
+ }
0 commit comments