-
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathitem.js
More file actions
40 lines (31 loc) · 1.29 KB
/
item.js
File metadata and controls
40 lines (31 loc) · 1.29 KB
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
import Route from '@ember/routing/route';
import { assert } from '@ember/debug';
export default Route.extend({
model({ path }) {
let item;
if (path.match(/^modules\//)) {
// Find by fully qualified id
let itemId = path.replace(/^modules\//, '');
let [moduleId] = itemId.split(/~|#/);
let module = this.store.peekRecord('module', moduleId);
item = module.get('components').findBy('id', itemId)
|| module.get('classes').findBy('id', itemId)
|| module;
} else {
// Create a regex that will match modules by either the path, or the
// pod-path (/component, /route, etc)
let type = path.match(/^(.*)s\//)[1];
let pathRegex = new RegExp(`${path}(/${type})?$`);
let modules = this.store.peekAll('module');
let matches = modules.filter(m => m.id.match(pathRegex));
let module = matches[0];
assert(`no modules match the path '${path}'`, matches.length > 0);
assert(`multiple modules match the path '${path}', ids: ${matches.mapBy('id').join(', ')}`, matches.length <= 1);
item = module.get('components').findBy('exportType', 'default')
|| module.get('classes').findBy('exportType', 'default')
|| module;
}
assert(`item not found for path '${path}'`, item);
return item;
}
});