-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathcontainer_debug_adapter.js
107 lines (90 loc) · 2.59 KB
/
container_debug_adapter.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
import Ember from 'ember-metal'; // Ember as namespace
import {
A as emberA,
typeOf,
String as StringUtils,
Namespace,
Object as EmberObject
} from 'ember-runtime';
/**
@module ember
@submodule ember-extension-support
*/
/**
The `ContainerDebugAdapter` helps the container and resolver interface
with tools that debug Ember such as the
[Ember Extension](https://github.com/tildeio/ember-extension)
for Chrome and Firefox.
This class can be extended by a custom resolver implementer
to override some of the methods with library-specific code.
The methods likely to be overridden are:
* `canCatalogEntriesByType`
* `catalogEntriesByType`
The adapter will need to be registered
in the application's container as `container-debug-adapter:main`.
Example:
```javascript
Application.initializer({
name: "containerDebugAdapter",
initialize(application) {
application.register('container-debug-adapter:main', require('app/container-debug-adapter'));
}
});
```
@class ContainerDebugAdapter
@namespace Ember
@extends Ember.Object
@since 1.5.0
@public
*/
export default EmberObject.extend({
/**
The resolver instance of the application
being debugged. This property will be injected
on creation.
@property resolver
@default null
@public
*/
resolver: null,
/**
Returns true if it is possible to catalog a list of available
classes in the resolver for a given type.
@method canCatalogEntriesByType
@param {String} type The type. e.g. "model", "controller", "route".
@return {boolean} whether a list is available for this type.
@public
*/
canCatalogEntriesByType(type) {
if (type === 'model' || type === 'template') {
return false;
}
return true;
},
/**
Returns the available classes a given type.
@method catalogEntriesByType
@param {String} type The type. e.g. "model", "controller", "route".
@return {Array} An array of strings.
@public
*/
catalogEntriesByType(type) {
let namespaces = emberA(Namespace.NAMESPACES);
let types = emberA();
let typeSuffixRegex = new RegExp(`${StringUtils.classify(type)}$`);
namespaces.forEach(namespace => {
if (namespace !== Ember) {
for (let key in namespace) {
if (!namespace.hasOwnProperty(key)) { continue; }
if (typeSuffixRegex.test(key)) {
let klass = namespace[key];
if (typeOf(klass) === 'class') {
types.push(StringUtils.dasherize(key.replace(typeSuffixRegex, '')));
}
}
}
}
});
return types;
}
});