forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_resolver.ts
More file actions
35 lines (27 loc) · 1 KB
/
view_resolver.ts
File metadata and controls
35 lines (27 loc) · 1 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
import {Injectable} from 'angular2/src/core/di';
import {ViewMetadata} from '../metadata/view';
import {Type, stringify, isBlank, BaseException} from 'angular2/src/core/facade/lang';
import {Map, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {reflector} from 'angular2/src/core/reflection/reflection';
@Injectable()
export class ViewResolver {
_cache: Map<Type, /*node*/ any> = new Map();
resolve(component: Type): ViewMetadata {
var view = this._cache.get(component);
if (isBlank(view)) {
view = this._resolve(component);
this._cache.set(component, view);
}
return view;
}
_resolve(component: Type): ViewMetadata {
var annotations = reflector.annotations(component);
for (var i = 0; i < annotations.length; i++) {
var annotation = annotations[i];
if (annotation instanceof ViewMetadata) {
return annotation;
}
}
throw new BaseException(`No View annotation found on component ${stringify(component)}`);
}
}