refactor(core): introduce ComponentFactory.
Each compile template now exposes a `<CompName>NgFactory` variable with an instance of a `ComponentFactory`. Calling `ComponentFactory.create` returns a `ComponentRef` that can be used directly. BREAKING CHANGE: - `Compiler` is renamed to `ComponentResolver`, `Compiler.compileInHost` has been renamed to `ComponentResolver.resolveComponent`. - `ComponentRef.dispose` is renamed to `ComponentRef.destroy` - `ViewContainerRef.createHostView` is renamed to `ViewContainerRef.createComponent` - `ComponentFixture_` has been removed, the class `ComponentFixture` can now be created directly as it is no more using private APIs.
This commit is contained in:
@ -6,7 +6,7 @@ import {ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DateWrapper, Type, print, isPresent} from 'angular2/src/facade/lang';
|
||||
|
||||
import {
|
||||
Compiler,
|
||||
ComponentResolver,
|
||||
Component,
|
||||
Directive,
|
||||
ViewContainerRef,
|
||||
@ -40,7 +40,7 @@ export function main() {
|
||||
BrowserDomAdapter.makeCurrent();
|
||||
bootstrap(CompilerAppComponent, _createBindings())
|
||||
.then((ref) => {
|
||||
var app = ref.hostComponent;
|
||||
var app = ref.instance;
|
||||
bindAction('#compileNoBindings',
|
||||
measureWrapper(() => app.compileNoBindings(), 'No Bindings'));
|
||||
bindAction('#compileWithBindings',
|
||||
@ -91,15 +91,15 @@ class MultiplyViewResolver extends ViewResolver {
|
||||
|
||||
@Component({selector: 'app', directives: [], template: ``})
|
||||
class CompilerAppComponent {
|
||||
constructor(private _compiler: Compiler) {}
|
||||
constructor(private _compiler: ComponentResolver) {}
|
||||
compileNoBindings() {
|
||||
this._compiler.clearCache();
|
||||
return this._compiler.compileInHost(BenchmarkComponentNoBindings);
|
||||
return this._compiler.resolveComponent(BenchmarkComponentNoBindings);
|
||||
}
|
||||
|
||||
compileWithBindings() {
|
||||
this._compiler.clearCache();
|
||||
return this._compiler.compileInHost(BenchmarkComponentWithBindings);
|
||||
return this._compiler.resolveComponent(BenchmarkComponentWithBindings);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ export function main() {
|
||||
bootstrap(AppComponent)
|
||||
.then((ref) => {
|
||||
var injector = ref.injector;
|
||||
var app: AppComponent = ref.hostComponent;
|
||||
var app: AppComponent = ref.instance;
|
||||
var appRef = injector.get(ApplicationRef);
|
||||
|
||||
bindAction('#reset', function() {
|
||||
|
@ -113,7 +113,7 @@ export function main() {
|
||||
bootstrap(AppComponent, _createBindings())
|
||||
.then((ref) => {
|
||||
var injector = ref.injector;
|
||||
app = ref.hostComponent;
|
||||
app = ref.instance;
|
||||
appRef = injector.get(ApplicationRef);
|
||||
bindAction('#ng2DestroyDom', ng2DestroyDom);
|
||||
bindAction('#ng2CreateDom', ng2CreateDom);
|
||||
|
@ -1,15 +1,6 @@
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {NgIf} from 'angular2/common';
|
||||
import {
|
||||
Compiler,
|
||||
Component,
|
||||
Directive,
|
||||
ViewContainerRef,
|
||||
bind,
|
||||
provide,
|
||||
Provider
|
||||
} from 'angular2/core';
|
||||
import {ComponentRef_} from 'angular2/src/core/linker/dynamic_component_loader';
|
||||
import {Component, Directive, ViewContainerRef, bind, provide, Provider} from 'angular2/core';
|
||||
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
||||
import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
|
||||
@ -94,10 +85,10 @@ export function main() {
|
||||
function initNg2() {
|
||||
bootstrap(AppComponentWithStaticTree, createBindings())
|
||||
.then((ref) => {
|
||||
var injector = (<ComponentRef_>ref).injector;
|
||||
var injector = ref.injector;
|
||||
appRef = injector.get(ApplicationRef);
|
||||
|
||||
app = (<ComponentRef_>ref).hostComponent;
|
||||
app = ref.instance;
|
||||
bindAction('#ng2DestroyDom', ng2DestroyDom);
|
||||
bindAction('#ng2CreateDom', ng2CreateDom);
|
||||
bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update'));
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {
|
||||
Compiler,
|
||||
Component,
|
||||
Directive,
|
||||
ViewContainerRef,
|
||||
@ -96,7 +95,7 @@ export function main() {
|
||||
var injector = ref.injector;
|
||||
appRef = injector.get(ApplicationRef);
|
||||
|
||||
app = ref.hostComponent;
|
||||
app = ref.instance;
|
||||
bindAction('#ng2DestroyDom', ng2DestroyDom);
|
||||
bindAction('#ng2CreateDom', ng2CreateDom);
|
||||
bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update'));
|
||||
|
Reference in New Issue
Block a user