refactor(core): type ComponentRef
, ComponentFactory
and ComponentFixture
by the component type
BREAKING CHANGE: - `ComponetRef`, `ComponentFactory`, `ComponentFixture` now all require a type parameter with the component type. Closes #8361
This commit is contained in:
@ -4,8 +4,9 @@ import {TypeScriptEmitter} from 'angular2/src/compiler/output/ts_emitter';
|
||||
import {DartEmitter} from 'angular2/src/compiler/output/dart_emitter';
|
||||
import {compileComp, compAMetadata} from './offline_compiler_util';
|
||||
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
|
||||
import {CompA} from './offline_compiler_util';
|
||||
|
||||
export const CompANgFactory: ComponentFactory = null;
|
||||
export const CompANgFactory: ComponentFactory<CompA> = null;
|
||||
|
||||
// Generator
|
||||
export function main(args: string[]) {
|
||||
|
@ -3,8 +3,9 @@ import {print} from 'angular2/src/facade/lang';
|
||||
import {JavaScriptEmitter} from 'angular2/src/compiler/output/js_emitter';
|
||||
import {compileComp, compAMetadata} from './offline_compiler_util';
|
||||
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
|
||||
import {CompA} from './offline_compiler_util';
|
||||
|
||||
export const CompANgFactory: ComponentFactory = null;
|
||||
export const CompANgFactory: ComponentFactory<CompA> = null;
|
||||
|
||||
// Generator
|
||||
export function main(args: string[]) {
|
||||
|
@ -16,7 +16,6 @@ import {
|
||||
|
||||
import {IS_DART} from 'angular2/src/facade/lang';
|
||||
import {Injector} from 'angular2/core';
|
||||
import {DebugNode, DebugElement, getDebugNode} from 'angular2/src/core/debug/debug_node';
|
||||
|
||||
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
|
||||
import * as typed from './offline_compiler_codegen_typed';
|
||||
@ -28,18 +27,18 @@ import {SharedStylesHost} from "angular2/src/platform/dom/shared_styles_host";
|
||||
import {CompA} from './offline_compiler_util';
|
||||
|
||||
export function main() {
|
||||
var outputDefs = [];
|
||||
var typedComponentFactory = typed.CompANgFactory;
|
||||
var untypedComponentFactory = untyped.CompANgFactory;
|
||||
var fixtures: TestFixture[] = [];
|
||||
|
||||
if (IS_DART || !DOM.supportsDOMEvents()) {
|
||||
// Our generator only works on node.js and Dart...
|
||||
outputDefs.push({'compAHostComponentFactory': typedComponentFactory, 'name': 'typed'});
|
||||
fixtures.push(new TestFixture(typedComponentFactory, 'typed'));
|
||||
}
|
||||
if (!IS_DART) {
|
||||
// Our generator only works on node.js and Dart...
|
||||
if (!DOM.supportsDOMEvents()) {
|
||||
outputDefs.push({'compAHostComponentFactory': untypedComponentFactory, 'name': 'untyped'});
|
||||
fixtures.push(new TestFixture(untypedComponentFactory, 'untyped'));
|
||||
}
|
||||
}
|
||||
describe('OfflineCompiler', () => {
|
||||
@ -51,16 +50,11 @@ export function main() {
|
||||
sharedStylesHost = _sharedStylesHost;
|
||||
}));
|
||||
|
||||
function createHostComp(cf: ComponentFactory): DebugElement {
|
||||
var compRef = cf.create(injector);
|
||||
return <DebugElement>getDebugNode(compRef.location.nativeElement);
|
||||
}
|
||||
|
||||
outputDefs.forEach((outputDef) => {
|
||||
describe(`${outputDef['name']}`, () => {
|
||||
fixtures.forEach((fixture) => {
|
||||
describe(`${fixture.name}`, () => {
|
||||
it('should compile components', () => {
|
||||
var hostEl = createHostComp(outputDef['compAHostComponentFactory']);
|
||||
expect(hostEl.componentInstance).toBeAnInstanceOf(CompA);
|
||||
var hostEl = fixture.compFactory.create(injector);
|
||||
expect(hostEl.instance).toBeAnInstanceOf(CompA);
|
||||
var styles = sharedStylesHost.getAllStyles();
|
||||
expect(styles[0]).toContain('.redStyle[_ngcontent');
|
||||
expect(styles[1]).toContain('.greenStyle[_ngcontent');
|
||||
@ -68,4 +62,8 @@ export function main() {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class TestFixture {
|
||||
constructor(public compFactory: ComponentFactory<CompA>, public name: string) {}
|
||||
}
|
Reference in New Issue
Block a user