refactor(ivy): `element` and `ElementStart` retuns `void` (#25173)
use `loadElement` to load an element when needed in specs PR Close #25173
This commit is contained in:
parent
89e8b6fc0e
commit
6a797d5401
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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], [],
|
||||
|
@ -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');
|
||||
}
|
||||
},
|
||||
|
@ -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');
|
||||
}
|
||||
},
|
||||
|
@ -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;
|
||||
}
|
||||
},
|
||||
[], [],
|
||||
|
@ -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');
|
||||
}
|
||||
},
|
||||
|
@ -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], [],
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue