refactor(ivy): simplify signature of appendChild / removeChild (#27987)

Previously the appendChild / removeChild could take null as an argument for
a child to be added / removed. This is difficult to understand since the
mentioned methods are noop if a child is null.

This commit clarifies the appendChild / removeChild signature to systematically
require a child node to be added removed. It turns out that null could be passed
only for a very specific i18n cases so now we guard a call to removeChild with
an explicit check on the i18n side.

PR Close #27987
This commit is contained in:
Pawel Kozlowski 2019-01-08 16:13:16 +01:00 committed by Kara Erickson
parent cc5fb914bc
commit b432eb1cae
2 changed files with 9 additions and 7 deletions

View File

@ -782,7 +782,10 @@ function readUpdateOpCodes(
function removeNode(index: number, viewData: LView) {
const removedPhTNode = getTNode(index, viewData);
const removedPhRNode = getNativeByIndex(index, viewData);
removeChild(removedPhTNode, removedPhRNode || null, viewData);
if (removedPhRNode) {
removeChild(removedPhTNode, removedPhRNode, viewData);
}
removedPhTNode.detached = true;
ngDevMode && ngDevMode.rendererRemoveNode++;
@ -790,7 +793,7 @@ function removeNode(index: number, viewData: LView) {
if (isLContainer(slotValue)) {
const lContainer = slotValue as LContainer;
if (removedPhTNode.type !== TNodeType.Container) {
removeChild(removedPhTNode, lContainer[NATIVE] || null, viewData);
removeChild(removedPhTNode, lContainer[NATIVE], viewData);
}
lContainer[RENDER_PARENT] = null;
}

View File

@ -631,9 +631,8 @@ export function nativeNextSibling(renderer: Renderer3, node: RNode): RNode|null
* @param currentView The current LView
* @returns Whether or not the child was appended
*/
export function appendChild(
childEl: RNode | null = null, childTNode: TNode, currentView: LView): boolean {
if (childEl !== null && canInsertNativeNode(childTNode, currentView)) {
export function appendChild(childEl: RNode, childTNode: TNode, currentView: LView): boolean {
if (canInsertNativeNode(childTNode, currentView)) {
const renderer = currentView[RENDERER];
const renderParent = getRenderParent(childTNode, currentView) !;
const parentTNode: TNode = childTNode.parent || currentView[HOST_NODE] !;
@ -690,9 +689,9 @@ export function getBeforeNodeForView(index: number, views: LView[], containerNat
* @param currentView The current LView
* @returns Whether or not the child was removed
*/
export function removeChild(childTNode: TNode, childEl: RNode | null, currentView: LView): boolean {
export function removeChild(childTNode: TNode, childEl: RNode, currentView: LView): boolean {
// We only remove the element if not in View or not projected.
if (childEl !== null && canInsertNativeNode(childTNode, currentView)) {
if (canInsertNativeNode(childTNode, currentView)) {
const parentNative = getRenderParent(childTNode, currentView) !;
nativeRemoveChild(currentView[RENDERER], parentNative, childEl);
return true;