Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Inline filler element has to be created as it is present in the DOM, but not in the view. It is required
// during diffing so text nodes could be compared correctly and also during rendering to maintain
// proper order and indexes while updating the DOM.
if ( inlineFillerPosition && inlineFillerPosition.parent === viewElement ) {
addInlineFiller( domElement.ownerDocument, expectedDomChildren, inlineFillerPosition.offset );
}
const diff = this._diffNodeLists( actualDomChildren, expectedDomChildren );
let i = 0;
const nodesToUnbind = new Set();
for ( const action of diff ) {
if ( action === 'insert' ) {
insertAt( domElement, i, expectedDomChildren[ i ] );
i++;
} else if ( action === 'delete' ) {
nodesToUnbind.add( actualDomChildren[ i ] );
remove( actualDomChildren[ i ] );
} else { // 'equal'
// Force updating text nodes inside elements which did not change and do not need to be re-rendered (#1125).
this._markDescendantTextToSync( this.domConverter.domToView( expectedDomChildren[ i ] ) );
i++;
}
}
// Unbind removed nodes. When node does not have a parent it means that it was removed from DOM tree during
// comparision with the expected DOM. We don't need to check child nodes, because if child node was reinserted,
// it was moved to DOM tree out of the removed node.
for ( const node of nodesToUnbind ) {
if ( !node.parentNode ) {
// Inline filler element has to be created as it is present in the DOM, but not in the view. It is required
// during diffing so text nodes could be compared correctly and also during rendering to maintain
// proper order and indexes while updating the DOM.
if ( inlineFillerPosition && inlineFillerPosition.parent === viewElement ) {
addInlineFiller( domElement.ownerDocument, expectedDomChildren, inlineFillerPosition.offset );
}
const diff = this._diffNodeLists( actualDomChildren, expectedDomChildren );
let i = 0;
const nodesToUnbind = new Set();
for ( const action of diff ) {
if ( action === 'insert' ) {
insertAt( domElement, i, expectedDomChildren[ i ] );
i++;
} else if ( action === 'delete' ) {
nodesToUnbind.add( actualDomChildren[ i ] );
remove( actualDomChildren[ i ] );
} else { // 'equal'
// Force updating text nodes inside elements which did not change and do not need to be re-rendered (#1125).
this._markDescendantTextToSync( this.domConverter.domToView( expectedDomChildren[ i ] ) );
i++;
}
}
// Unbind removed nodes. When node does not have a parent it means that it was removed from DOM tree during
// comparision with the expected DOM. We don't need to check child nodes, because if child node was reinserted,
// it was moved to DOM tree out of the removed node.
for ( const node of nodesToUnbind ) {
if ( !node.parentNode ) {
function addInlineFiller( domDocument, domParentOrArray, offset ) {
const childNodes = domParentOrArray instanceof Array ? domParentOrArray : domParentOrArray.childNodes;
const nodeAfterFiller = childNodes[ offset ];
if ( isText( nodeAfterFiller ) ) {
nodeAfterFiller.data = INLINE_FILLER + nodeAfterFiller.data;
return nodeAfterFiller;
} else {
const fillerNode = domDocument.createTextNode( INLINE_FILLER );
if ( Array.isArray( domParentOrArray ) ) {
childNodes.splice( offset, 0, fillerNode );
} else {
insertAt( domParentOrArray, offset, fillerNode );
}
return fillerNode;
}
}
function addInlineFiller( domDocument, domParentOrArray, offset ) {
const childNodes = domParentOrArray instanceof Array ? domParentOrArray : domParentOrArray.childNodes;
const nodeAfterFiller = childNodes[ offset ];
if ( isText( nodeAfterFiller ) ) {
nodeAfterFiller.data = INLINE_FILLER + nodeAfterFiller.data;
return nodeAfterFiller;
} else {
const fillerNode = domDocument.createTextNode( INLINE_FILLER );
if ( Array.isArray( domParentOrArray ) ) {
childNodes.splice( offset, 0, fillerNode );
} else {
insertAt( domParentOrArray, offset, fillerNode );
}
return fillerNode;
}
}