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