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:
Tobias Bosch
2016-04-13 17:05:17 -07:00
parent 41404057cf
commit 0c600cf6e3
66 changed files with 611 additions and 849 deletions
@@ -24,7 +24,7 @@ import {provide, Inject, Injector, PLATFORM_INITIALIZER, APP_INITIALIZER} from '
import {disposePlatform} from 'angular2/src/core/application_ref';
import {ExceptionHandler, BaseException} from 'angular2/src/facade/exceptions';
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
import {ComponentRef_, ComponentRef} from "angular2/src/core/linker/dynamic_component_loader";
import {ComponentRef} from "angular2/src/core/linker/component_factory";
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
class HelloRootCmp {
@@ -194,7 +194,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
bootstrap(HelloOnDestroyTickCmp, testProviders)
.then((ref) => {
expect(() => ref.dispose()).not.toThrow();
expect(() => ref.destroy()).not.toThrow();
async.done();
});
}));
@@ -204,7 +204,7 @@ export function main() {
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, testProviders]);
app.bootstrap(HelloRootCmp)
.then((ref) => {
ref.dispose();
ref.destroy();
expect(() => app.tick()).not.toThrow();
async.done();
});
@@ -216,7 +216,7 @@ export function main() {
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
refPromise.then((ref) => {
expect(ref.hostComponent.appBinding).toEqual("BoundValue");
expect(ref.instance.appBinding).toEqual("BoundValue");
async.done();
});
}));
@@ -226,7 +226,7 @@ export function main() {
var refPromise = bootstrap(HelloRootCmp4, testProviders);
refPromise.then((ref) => {
expect(ref.hostComponent.appRef).toBe((<ComponentRef_>ref).injector.get(ApplicationRef));
expect(ref.instance.appRef).toBe(ref.injector.get(ApplicationRef));
async.done();
});
}));
@@ -1,8 +1,8 @@
import 'package:angular2/testing_internal.dart' show SpyObject;
import 'package:angular2/core.dart' show Injector, bind;
import 'package:angular2/src/core/application_ref.dart' show ApplicationRef;
import 'package:angular2/src/core/linker/dynamic_component_loader.dart'
show ComponentRef_;
import 'package:angular2/src/core/linker/component_factory.dart'
show ComponentRef;
import 'dart:js';
@proxy
@@ -11,7 +11,7 @@ class SpyApplicationRef extends SpyObject implements ApplicationRef {
}
@proxy
class SpyComponentRef extends SpyObject implements ComponentRef_ {
class SpyComponentRef extends SpyObject implements ComponentRef {
Injector injector;
SpyComponentRef() {
@@ -1,6 +1,5 @@
import {SpyObject} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {global} from 'angular2/src/facade/lang';
import {ApplicationRef, ApplicationRef_} from 'angular2/src/core/application_ref';