refactor(view_compiler): codegen DI and Queries

BREAKING CHANGE:
- Renderer:
  * renderComponent method is removed form `Renderer`, only present on `RootRenderer`
  * Renderer.setDebugInfo is removed. Renderer.createElement / createText / createTemplateAnchor
    now take the DebugInfo directly.
- Query semantics:
  * Queries don't work with dynamically loaded components.
  * e.g. for router-outlet: loaded components can't be queries via @ViewQuery,
    but router-outlet emits an event `activate` now that emits the activated component
- Exception classes and the context inside changed (renamed fields)
- DebugElement.attributes is an Object and not a Map in JS any more
- ChangeDetectorGenConfig was renamed into CompilerConfig
- AppViewManager.createEmbeddedViewInContainer / AppViewManager.createHostViewInContainer
  are removed, use the methods in ViewContainerRef instead
- Change detection order changed:
  * 1. dirty check component inputs
  * 2. dirty check content children
  * 3. update render nodes

Closes #6301
Closes #6567
This commit is contained in:
Tobias Bosch
2016-01-06 14:13:44 -08:00
parent 45f09ba686
commit 2b34c88b69
312 changed files with 14271 additions and 16566 deletions

View File

@ -27,23 +27,21 @@ function detectChangesAndCheck(fixture: ComponentFixture, classes: string) {
export function main() {
describe('binding to CSS class list', () => {
describe('viewpool support', () => {
it('should clean up when the directive is destroyed',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div *ngFor="var item of items" [ngClass]="item"></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.items = [['0']];
fixture.detectChanges();
fixture.debugElement.componentInstance.items = [['1']];
it('should clean up when the directive is destroyed',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div *ngFor="var item of items" [ngClass]="item"></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.items = [['0']];
fixture.detectChanges();
fixture.debugElement.componentInstance.items = [['1']];
detectChangesAndCheck(fixture, '1');
detectChangesAndCheck(fixture, '1');
async.done();
});
}));
});
async.done();
});
}));
describe('expressions evaluating to objects', () => {

View File

@ -17,8 +17,6 @@ import {
import {SpyNgControl, SpyValueAccessor} from '../spies';
import {QueryList} from 'angular2/core';
import {
ControlGroup,
Control,

View File

@ -12,7 +12,7 @@ import {
import {DatePipe} from 'angular2/common';
import {DateWrapper} from 'angular2/src/facade/lang';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
import {PipeResolver} from 'angular2/src/compiler/pipe_resolver';
export function main() {
describe("DatePipe", () => {

View File

@ -10,7 +10,7 @@ import {
} from 'angular2/testing_internal';
import {I18nPluralPipe} from 'angular2/common';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
import {PipeResolver} from 'angular2/src/compiler/pipe_resolver';
export function main() {
describe("I18nPluralPipe", () => {

View File

@ -10,7 +10,7 @@ import {
} from 'angular2/testing_internal';
import {I18nSelectPipe} from 'angular2/common';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
import {PipeResolver} from 'angular2/src/compiler/pipe_resolver';
export function main() {
describe("I18nSelectPipe", () => {

View File

@ -1,26 +0,0 @@
import {
ddescribe,
xdescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider';
import {Pipe} from 'angular2/src/core/metadata';
class MyPipe {}
export function main() {
describe("PipeProvider", () => {
it('should create a provider out of a type', () => {
var provider = PipeProvider.createFromType(MyPipe, new Pipe({name: 'my-pipe'}));
expect(provider.name).toEqual('my-pipe');
expect(provider.key.token).toEqual(MyPipe);
});
});
}

View File

@ -1,76 +0,0 @@
import {
ddescribe,
xdescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {Injector, Inject, provide, Pipe, PipeTransform, OnDestroy} from 'angular2/core';
import {ProtoPipes, Pipes} from 'angular2/src/core/pipes/pipes';
import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider';
class PipeA implements PipeTransform, OnDestroy {
transform(a, b) {}
ngOnDestroy() {}
}
class PipeB implements PipeTransform, OnDestroy {
dep;
constructor(@Inject("dep") dep: any) { this.dep = dep; }
transform(a, b) {}
ngOnDestroy() {}
}
export function main() {
describe("Pipes", () => {
var injector;
beforeEach(() => {
injector = Injector.resolveAndCreate([provide('dep', {useValue: 'dependency'})]);
});
it('should instantiate a pipe', () => {
var proto =
ProtoPipes.fromProviders([PipeProvider.createFromType(PipeA, new Pipe({name: 'a'}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pipe).toBeAnInstanceOf(PipeA);
});
it('should throw when no pipe found', () => {
var proto = ProtoPipes.fromProviders([]);
var pipes = new Pipes(proto, injector);
expect(() => pipes.get("invalid")).toThrowErrorWith("Cannot find pipe 'invalid'");
});
it('should inject dependencies from the provided injector', () => {
var proto =
ProtoPipes.fromProviders([PipeProvider.createFromType(PipeB, new Pipe({name: 'b'}))]);
var pipes = new Pipes(proto, injector);
expect((<any>pipes.get("b").pipe).dep).toEqual("dependency");
});
it('should cache pure pipes', () => {
var proto = ProtoPipes.fromProviders(
[PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: true}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pure).toEqual(true);
expect(pipes.get("a")).toBe(pipes.get("a"));
});
it('should NOT cache impure pipes', () => {
var proto = ProtoPipes.fromProviders(
[PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: false}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pure).toEqual(false);
expect(pipes.get("a")).not.toBe(pipes.get("a"));
});
});
}