feat(ComponentUrlMapper): retrieve the base URL for components

This commit is contained in:
Victor Berchet 2015-02-23 14:24:15 +01:00
parent 9250cd6a78
commit 26872f60e6
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import {Type, isPresent} from 'angular2/src/facade/lang';
import {Map, MapWrapper} from 'angular2/src/facade/lang';
export class ComponentUrlMapper {
// Returns the url to the component source file.
// The returned url could be:
// - an absolute URL,
// - a URL relative to the application
getUrl(component: Type): string {
return './';
}
}
export class RuntimeComponentUrlMapper extends ComponentUrlMapper {
_componentUrls: Map;
constructor() {
super();
this._componentUrls = MapWrapper.create();
}
setComponentUrl(component: Type, url: string) {
MapWrapper.set(this._componentUrls, component, url);
}
getUrl(component: Type): string {
var url = MapWrapper.get(this._componentUrls, component);
if (isPresent(url)) return url;
return super.getUrl(component);
}
}