2015-12-02 10:35:51 -08:00
|
|
|
import {HostViewFactoryRef} from 'angular2/src/core/linker/view_ref';
|
2015-10-01 10:07:49 -07:00
|
|
|
|
|
|
|
import {Injectable} from 'angular2/src/core/di';
|
2015-11-06 17:34:07 -08:00
|
|
|
import {Type, isBlank, stringify} from 'angular2/src/facade/lang';
|
|
|
|
import {BaseException} from 'angular2/src/facade/exceptions';
|
2016-02-08 13:24:09 -08:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/async';
|
2015-10-01 10:07:49 -07:00
|
|
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
2015-12-02 10:35:51 -08:00
|
|
|
import {HostViewFactory} from 'angular2/src/core/linker/view';
|
|
|
|
import {HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
|
2015-05-20 09:48:15 -07:00
|
|
|
|
2015-09-18 15:46:26 -07:00
|
|
|
/**
|
2015-09-21 12:32:25 -07:00
|
|
|
* Low-level service for compiling {@link Component}s into {@link ProtoViewRef ProtoViews}s, which
|
|
|
|
* can later be used to create and render a Component instance.
|
2015-09-18 15:46:26 -07:00
|
|
|
*
|
2015-09-21 12:32:25 -07:00
|
|
|
* Most applications should instead use higher-level {@link DynamicComponentLoader} service, which
|
|
|
|
* both compiles and instantiates a Component.
|
2015-09-18 15:46:26 -07:00
|
|
|
*/
|
2015-10-06 06:53:39 -07:00
|
|
|
export abstract class Compiler {
|
2015-12-02 10:35:51 -08:00
|
|
|
abstract compileInHost(componentType: Type): Promise<HostViewFactoryRef>;
|
2015-10-06 06:53:39 -07:00
|
|
|
abstract clearCache();
|
|
|
|
}
|
|
|
|
|
2015-12-02 10:35:51 -08:00
|
|
|
function isHostViewFactory(type: any): boolean {
|
|
|
|
return type instanceof HostViewFactory;
|
2015-10-22 23:35:53 -07:00
|
|
|
}
|
|
|
|
|
2015-05-20 09:48:15 -07:00
|
|
|
@Injectable()
|
2015-10-06 06:53:39 -07:00
|
|
|
export class Compiler_ extends Compiler {
|
2015-12-02 10:35:51 -08:00
|
|
|
compileInHost(componentType: Type): Promise<HostViewFactoryRef_> {
|
2015-10-01 10:07:49 -07:00
|
|
|
var metadatas = reflector.annotations(componentType);
|
2015-12-02 10:35:51 -08:00
|
|
|
var hostViewFactory = metadatas.find(isHostViewFactory);
|
2015-10-22 23:35:53 -07:00
|
|
|
|
2015-12-02 10:35:51 -08:00
|
|
|
if (isBlank(hostViewFactory)) {
|
|
|
|
throw new BaseException(`No precompiled component ${stringify(componentType)} found`);
|
2015-05-20 09:48:15 -07:00
|
|
|
}
|
2015-12-02 10:35:51 -08:00
|
|
|
return PromiseWrapper.resolve(new HostViewFactoryRef_(hostViewFactory));
|
2015-05-21 16:42:19 +02:00
|
|
|
}
|
2015-05-20 09:48:15 -07:00
|
|
|
|
2015-12-02 10:35:51 -08:00
|
|
|
clearCache() {}
|
2015-10-02 07:37:23 -07:00
|
|
|
}
|