feat(core): add a component resolver that can load components lazily using system.js
This commit is contained in:
parent
0f1465b899
commit
1a0aea67a0
|
@ -19,6 +19,7 @@ export {
|
|||
SourceModule,
|
||||
NormalizedComponentWithViewDirectives,
|
||||
OfflineCompiler,
|
||||
RuntimeCompiler,
|
||||
CompileMetadataWithIdentifier,
|
||||
CompileMetadataWithType,
|
||||
CompileIdentifierMetadata,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Public API for compiler
|
||||
export {ComponentResolver} from './linker/component_resolver';
|
||||
export {SystemJsComponentResolver} from './linker/systemjs_component_resolver';
|
||||
export {QueryList} from './linker/query_list';
|
||||
export {DynamicComponentLoader} from './linker/dynamic_component_loader';
|
||||
export {ElementRef} from './linker/element_ref';
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import { ComponentResolver } from './component_resolver';
|
||||
import { Type, isString, global } from '../../src/facade/lang';
|
||||
import { ComponentFactory } from './component_factory';
|
||||
|
||||
/**
|
||||
* Component resolver that can load components lazily
|
||||
*/
|
||||
export class SystemJsComponentResolver implements ComponentResolver {
|
||||
constructor(private _resolver: ComponentResolver) {}
|
||||
|
||||
resolveComponent(componentType:string|Type):Promise<ComponentFactory<any>> {
|
||||
if (isString(componentType)) {
|
||||
return (<any>global).System.import(componentType).then(module =>
|
||||
this._resolver.resolveComponent(module.default));
|
||||
} else {
|
||||
return this._resolver.resolveComponent(<Type>componentType);
|
||||
}
|
||||
}
|
||||
|
||||
clearCache() {}
|
||||
}
|
|
@ -140,6 +140,7 @@ var COMPILER: string[] = [
|
|||
"DirectiveResolver",
|
||||
"NormalizedComponentWithViewDirectives",
|
||||
"OfflineCompiler",
|
||||
"RuntimeCompiler",
|
||||
"PipeResolver",
|
||||
"ProviderAst",
|
||||
"ProviderAstType",
|
||||
|
@ -185,6 +186,7 @@ var CORE: string[] = [
|
|||
'ChangeDetectorRef',
|
||||
'Class:js',
|
||||
'ComponentResolver',
|
||||
'SystemJsComponentResolver',
|
||||
'Component',
|
||||
'ComponentMetadata',
|
||||
'ComponentRef',
|
||||
|
|
|
@ -11,7 +11,7 @@ import {reflector} from '@angular/core';
|
|||
// TODO: vsavkin: recognize should take the old tree and merge it
|
||||
export function recognize(componentResolver: ComponentResolver, rootComponent: Type,
|
||||
url: UrlTree): Promise<RouteTree> {
|
||||
let matched = new _MatchResult(rootComponent, [url.root], null, rootNode(url).children, []);
|
||||
let matched = new _MatchResult(rootComponent, [url.root], {}, rootNode(url).children, []);
|
||||
return _constructSegment(componentResolver, matched).then(roots => new RouteTree(roots[0]));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue