MCPcopy Create free account
hub / github.com/angular/angular / replaceLViewInTree

Function replaceLViewInTree

packages/core/src/render3/hmr.ts:361–395  ·  view source on GitHub ↗

* Replaces one LView in the tree with another one. * @param parentLView Parent of the LView being replaced. * @param oldLView LView being replaced. * @param newLView Replacement LView to be inserted. * @param index Index at which the LView should be inserted.

(
  parentLView: LView,
  oldLView: LView,
  newLView: LView,
  index: number,
)

Source from the content-addressed store, hash-verified

359 * @param index Index at which the LView should be inserted.
360 */
361function replaceLViewInTree(
362 parentLView: LView,
363 oldLView: LView,
364 newLView: LView,
365 index: number,
366): void {
367 // Update the sibling whose `NEXT` pointer refers to the old view.
368 for (let i = HEADER_OFFSET; i < parentLView[TVIEW].bindingStartIndex; i++) {
369 const current = parentLView[i];
370
371 if ((isLView(current) || isLContainer(current)) && current[NEXT] === oldLView) {
372 current[NEXT] = newLView;
373 break;
374 }
375 }
376
377 // Set the new view as the head, if the old view was first.
378 if (parentLView[CHILD_HEAD] === oldLView) {
379 parentLView[CHILD_HEAD] = newLView;
380 }
381
382 // Set the new view as the tail, if the old view was last.
383 if (parentLView[CHILD_TAIL] === oldLView) {
384 parentLView[CHILD_TAIL] = newLView;
385 }
386
387 // Update the `NEXT` pointer to the same as the old view.
388 newLView[NEXT] = oldLView[NEXT];
389
390 // Clear out the `NEXT` of the old view.
391 oldLView[NEXT] = null;
392
393 // Insert the new LView at the correct index.
394 parentLView[index] = newLView;
395}
396
397/**
398 * Child nodes mutate the `projection` state of their parent node as they're being projected.

Callers 1

recreateFunction · 0.85

Calls 2

isLViewFunction · 0.90
isLContainerFunction · 0.90

Tested by

no test coverage detected