2015-06-30 13:18:51 -07:00
|
|
|
import {RouteHandler} from './route_handler';
|
2015-11-06 17:34:07 -08:00
|
|
|
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
|
|
|
import {isPresent, Type} from 'angular2/src/facade/lang';
|
2015-06-30 13:18:51 -07:00
|
|
|
|
|
|
|
export class AsyncRouteHandler implements RouteHandler {
|
2015-10-09 17:21:25 -07:00
|
|
|
/** @internal */
|
2015-06-30 13:18:51 -07:00
|
|
|
_resolvedComponent: Promise<any> = null;
|
|
|
|
componentType: Type;
|
|
|
|
|
2015-09-30 14:48:58 +02:00
|
|
|
constructor(private _loader: Function, public data?: {[key: string]: any}) {}
|
2015-06-30 13:18:51 -07:00
|
|
|
|
|
|
|
resolveComponentType(): Promise<any> {
|
|
|
|
if (isPresent(this._resolvedComponent)) {
|
|
|
|
return this._resolvedComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._resolvedComponent = this._loader().then((componentType) => {
|
|
|
|
this.componentType = componentType;
|
|
|
|
return componentType;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|