Skip to content

Commit

Permalink
refactor(ivy): element and ElementStart retuns void (angular#25173
Browse files Browse the repository at this point in the history
)

use `loadElement` to load an element when needed in specs

PR Close angular#25173
  • Loading branch information
vicb authored and IgorMinar committed Jul 28, 2018
1 parent 89e8b6f commit 6a797d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
11 changes: 4 additions & 7 deletions packages/core/src/render3/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,9 @@ export function namespaceHTML() {
* @param localRefs A set of local reference bindings on the element.
*/
export function element(
index: number, name: string, attrs?: TAttributes | null,
localRefs?: string[] | null): RElement {
const rElement = elementStart(index, name, attrs, localRefs);
index: number, name: string, attrs?: TAttributes | null, localRefs?: string[] | null): void {
elementStart(index, name, attrs, localRefs);
elementEnd();
return rElement;
}

/**
Expand All @@ -655,8 +653,7 @@ export function element(
* ['id', 'warning5', 'class', 'alert']
*/
export function elementStart(
index: number, name: string, attrs?: TAttributes | null,
localRefs?: string[] | null): RElement {
index: number, name: string, attrs?: TAttributes | null, localRefs?: string[] | null): void {
ngDevMode &&
assertEqual(viewData[BINDING_INDEX], -1, 'elements should be created before any bindings');

Expand All @@ -675,8 +672,8 @@ export function elementStart(
}
appendChild(getParentLNode(node), native, viewData);
createDirectivesAndLocals(localRefs);
return native;
}

/**
* Creates a native element from a tag name, using a renderer.
* @param name the tag name
Expand Down
50 changes: 33 additions & 17 deletions packages/core/test/render3/query_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ElementRef, TemplateRef, ViewContainerRef} from '@angular/core';
import {EventEmitter} from '../..';
import {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF, getOrCreateNodeInjectorForNode, getOrCreateTemplateRef} from '../../src/render3/di';
import {AttributeMarker, QueryList, defineComponent, defineDirective, detectChanges, injectViewContainerRef} from '../../src/render3/index';
import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load, loadDirective, loadQueryList, registerContentQuery} from '../../src/render3/instructions';
import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load, loadDirective, loadElement, loadQueryList, registerContentQuery} from '../../src/render3/instructions';
import {RenderFlags} from '../../src/render3/interfaces/definition';
import {query, queryRefresh} from '../../src/render3/query';

Expand Down Expand Up @@ -111,7 +111,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
elToQuery = element(1, 'div', ['child', '']);
element(1, 'div', ['child', '']);
elToQuery = loadElement(1).native;
}
},
[Child], [],
Expand Down Expand Up @@ -217,7 +218,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
elToQuery = element(1, 'div', null, ['foo', '']);
element(1, 'div', null, ['foo', '']);
elToQuery = loadElement(1).native;
element(3, 'div');
}
},
Expand Down Expand Up @@ -253,7 +255,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
elToQuery = element(2, 'div', null, ['foo', '', 'bar', '']);
element(2, 'div', null, ['foo', '', 'bar', '']);
elToQuery = loadElement(2).native;
element(5, 'div');
}
},
Expand Down Expand Up @@ -299,9 +302,11 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
el1ToQuery = element(1, 'div', null, ['foo', '']);
element(1, 'div', null, ['foo', '']);
el1ToQuery = loadElement(1).native;
element(3, 'div');
el2ToQuery = element(4, 'div', null, ['bar', '']);
element(4, 'div', null, ['bar', '']);
el2ToQuery = loadElement(4).native;
}
},
[], [],
Expand Down Expand Up @@ -336,7 +341,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
elToQuery = element(1, 'div', null, ['foo', '']);
element(1, 'div', null, ['foo', '']);
elToQuery = loadElement(1).native;
element(3, 'div');
}
},
Expand Down Expand Up @@ -739,7 +745,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
div = element(1, 'div', ['child', ''], ['foo', 'child']);
element(1, 'div', ['child', ''], ['foo', 'child']);
div = loadElement(1).native;
}
},
[Child], [],
Expand Down Expand Up @@ -773,7 +780,8 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
div = element(1, 'div', ['child', ''], ['foo', '', 'bar', 'child']);
element(1, 'div', ['child', ''], ['foo', '', 'bar', 'child']);
div = loadElement(1).native;
}
if (rf & RenderFlags.Update) {
childInstance = loadDirective(0);
Expand Down Expand Up @@ -1239,7 +1247,8 @@ describe('query', () => {
let rf1 = embeddedViewStart(1);
{
if (rf1 & RenderFlags.Create) {
firstEl = element(0, 'div', null, ['foo', '']);
element(0, 'div', null, ['foo', '']);
firstEl = loadElement(0).native;
}
}
embeddedViewEnd();
Expand Down Expand Up @@ -1290,9 +1299,11 @@ describe('query', () => {
'cmpt',
function(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
firstEl = element(1, 'span', null, ['foo', '']);
element(1, 'span', null, ['foo', '']);
firstEl = loadElement(1).native;
container(3);
lastEl = element(4, 'span', null, ['foo', '']);
element(4, 'span', null, ['foo', '']);
lastEl = loadElement(4).native;
}
if (rf & RenderFlags.Update) {
containerRefreshStart(3);
Expand All @@ -1301,7 +1312,8 @@ describe('query', () => {
let rf1 = embeddedViewStart(1);
{
if (rf1 & RenderFlags.Create) {
viewEl = element(0, 'div', null, ['foo', '']);
element(0, 'div', null, ['foo', '']);
viewEl = loadElement(0).native;
}
}
embeddedViewEnd();
Expand Down Expand Up @@ -1367,7 +1379,8 @@ describe('query', () => {
let rf0 = embeddedViewStart(0);
{
if (rf0 & RenderFlags.Create) {
firstEl = element(0, 'div', null, ['foo', '']);
element(0, 'div', null, ['foo', '']);
firstEl = loadElement(0).native;
}
}
embeddedViewEnd();
Expand All @@ -1376,7 +1389,8 @@ describe('query', () => {
let rf1 = embeddedViewStart(1);
{
if (rf1 & RenderFlags.Create) {
lastEl = element(0, 'span', null, ['foo', '']);
element(0, 'span', null, ['foo', '']);
lastEl = loadElement(0).native;
}
}
embeddedViewEnd();
Expand Down Expand Up @@ -1438,7 +1452,8 @@ describe('query', () => {
let rf0 = embeddedViewStart(0);
{
if (rf0 & RenderFlags.Create) {
firstEl = element(0, 'div', null, ['foo', '']);
element(0, 'div', null, ['foo', '']);
firstEl = loadElement(0).native;
container(2);
}
if (rf0 & RenderFlags.Update) {
Expand All @@ -1448,7 +1463,8 @@ describe('query', () => {
let rf2 = embeddedViewStart(0);
{
if (rf2) {
lastEl = element(0, 'span', null, ['foo', '']);
element(0, 'span', null, ['foo', '']);
lastEl = loadElement(0).native;
}
}
embeddedViewEnd();
Expand Down

0 comments on commit 6a797d5

Please sign in to comment.