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

View File

@ -66,7 +66,7 @@ Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
for (var reflectable in viewDefResults.viewDefinitions.keys) {
// TODO(kegluneq): Avoid duplicating naming logic for generated classes.
reflectable.annotations.add(new AnnotationModel()
..name = 'hostViewFactory_${reflectable.name}'
..name = '${reflectable.name}NgFactory'
..isConstObject = true);
}
}

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [
const [MyContext]
], (MyContext c) => new MyComponent(c)));
i0.initReflector();

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -16,7 +16,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Annotation1(prop1: 'value1'),
const Annotation2(prop2: 'value2'),
hostViewFactory_MyComponent
MyComponentNgFactory
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -16,7 +16,7 @@ void initReflector() {
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(
const [hostViewFactory_MyComponent],
const [MyComponentNgFactory],
const [
const [prefix.MyContext],
const [prefix.MyDep]

View File

@ -114,7 +114,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
..toContain('$CONTEXT_ACCESSOR.greeting')
@ -132,7 +132,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))..toContain('$CONTEXT_ACCESSOR.action()');
});
@ -158,7 +158,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
@ -188,7 +188,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
@ -216,7 +216,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))