refactor(ivy): remove dynamicParent from LNode (#24678)

PR Close #24678
This commit is contained in:
Kara Erickson
2018-06-26 11:39:56 -07:00
committed by Jason Aden
parent 5c0e681bf3
commit fe8fcc834c
9 changed files with 93 additions and 54 deletions

View File

@ -8,6 +8,9 @@
{
"name": "CLEAN_PROMISE"
},
{
"name": "CONTAINER_INDEX"
},
{
"name": "CONTEXT"
},

View File

@ -17,6 +17,9 @@
{
"name": "CLEAN_PROMISE"
},
{
"name": "CONTAINER_INDEX"
},
{
"name": "CONTEXT"
},

View File

@ -14,7 +14,7 @@ import {RenderFlags} from '../../src/render3/interfaces/definition';
import {pipe, pipeBind1} from '../../src/render3/pipe';
import {getRendererFactory2} from './imported_renderer2';
import {ComponentFixture, TemplateFixture} from './render_util';
import {ComponentFixture, TemplateFixture, createComponent} from './render_util';
describe('ViewContainerRef', () => {
let directiveInstance: DirectiveWithVCRef|null;
@ -101,14 +101,8 @@ describe('ViewContainerRef', () => {
});
it('should work on components', () => {
class HeaderComponent {
static ngComponentDef = defineComponent({
type: HeaderComponent,
selectors: [['header-cmp']],
factory: () => new HeaderComponent(),
template: (rf: RenderFlags, cmp: HeaderComponent) => {}
});
}
const HeaderComponent =
createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {});
function createTemplate() {
container(0, embeddedTemplate);
@ -139,6 +133,38 @@ describe('ViewContainerRef', () => {
expect(() => { createView('Z', 5); }).toThrow();
});
it('should work with multiple instances with vcrefs', () => {
let firstDir: DirectiveWithVCRef;
let secondDir: DirectiveWithVCRef;
function createTemplate() {
container(0, embeddedTemplate);
elementStart(1, 'div', ['vcref', '']);
elementEnd();
elementStart(2, 'div', ['vcref', '']);
elementEnd();
// for testing only:
firstDir = loadDirective(0);
secondDir = loadDirective(1);
}
function update() {
// Hack until we can create local refs to templates
const tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(1, 'tplRef', bind(tplRef));
elementProperty(2, 'tplRef', bind(tplRef));
}
const fixture = new TemplateFixture(createTemplate, update, [DirectiveWithVCRef]);
expect(fixture.html).toEqual('<div vcref=""></div><div vcref=""></div>');
firstDir !.vcref.createEmbeddedView(firstDir !.tplRef, {name: 'A'});
secondDir !.vcref.createEmbeddedView(secondDir !.tplRef, {name: 'B'});
fixture.update();
expect(fixture.html).toEqual('<div vcref=""></div>A<div vcref=""></div>B');
});
it('should work on containers', () => {
function createTemplate() {
container(0, embeddedTemplate, undefined, ['vcref', '']);
@ -277,7 +303,7 @@ describe('ViewContainerRef', () => {
/**
* before|
* <ng-template directive>A<ng-template>
* <ng-template testDir>A<ng-template>
* % if (condition) {
* B
* % }