MCPcopy Create free account
hub / github.com/angular/angular / ɵɵrepeater

Function ɵɵrepeater

packages/core/src/render3/instructions/control_flow.ts:501–589  ·  view source on GitHub ↗
(collection: Iterable<unknown> | undefined | null)

Source from the content-addressed store, hash-verified

499 * @codeGenApi
500 */
501export function ɵɵrepeater(collection: Iterable<unknown> | undefined | null): void {
502 const prevConsumer = setActiveConsumer(null);
503 const metadataSlotIdx = getSelectedIndex();
504 try {
505 const hostLView = getLView();
506 const hostTView = hostLView[TVIEW];
507 const metadata = hostLView[metadataSlotIdx] as RepeaterMetadata;
508 const containerIndex = metadataSlotIdx + 1;
509 const lContainer = getLContainer(hostLView, containerIndex);
510
511 if (metadata.liveCollection === undefined) {
512 const itemTemplateTNode = getExistingTNode(hostTView, containerIndex);
513 metadata.liveCollection = new LiveCollectionLContainerImpl(
514 lContainer,
515 hostLView,
516 itemTemplateTNode,
517 );
518 } else {
519 metadata.liveCollection.reset();
520 }
521
522 const liveCollection = metadata.liveCollection;
523 reconcile(liveCollection, collection, metadata.trackByFn, prevConsumer);
524
525 // Warn developers about situations where the entire collection was re-created as part of the
526 // reconciliation pass. Note that this warning might be "overreacting" and report cases where
527 // the collection re-creation is the intended behavior. Still, the assumption is that most of
528 // the time it is undesired.
529 if (
530 ngDevMode &&
531 metadata.trackByFn === ɵɵrepeaterTrackByIdentity &&
532 liveCollection.operationsCounter?.wasReCreated(liveCollection.length) &&
533 isViewExpensiveToRecreate(getExistingLViewFromLContainer(lContainer, 0))
534 ) {
535 const message = formatRuntimeError(
536 RuntimeErrorCode.LOOP_TRACK_RECREATE,
537 `The configured tracking expression (track by identity) caused re-creation of the entire collection of size ${liveCollection.length}. ` +
538 'This is an expensive operation requiring destruction and subsequent creation of DOM nodes, directives, components etc. ' +
539 'Please review the "track expression" and make sure that it uniquely identifies items in a collection.',
540 );
541 console.warn(message);
542 }
543
544 // moves in the container might caused context's index to get out of order, re-adjust if needed
545 liveCollection.updateIndexes();
546
547 // handle empty blocks
548 if (metadata.hasEmptyBlock) {
549 const bindingIndex = nextBindingIndex();
550 const isCollectionEmpty = liveCollection.length === 0;
551 if (bindingUpdated(hostLView, bindingIndex, isCollectionEmpty)) {
552 const emptyTemplateIndex = metadataSlotIdx + 2;
553 const lContainerForEmpty = getLContainer(hostLView, emptyTemplateIndex);
554 if (isCollectionEmpty) {
555 const emptyTemplateTNode = getExistingTNode(hostTView, emptyTemplateIndex);
556 const dehydratedView = findAndReconcileMatchingDehydratedViews(
557 lContainerForEmpty,
558 emptyTemplateTNode,

Callers

nothing calls this directly

Calls 15

setActiveConsumerFunction · 0.90
getSelectedIndexFunction · 0.90
getLViewFunction · 0.90
reconcileFunction · 0.90
formatRuntimeErrorFunction · 0.90
nextBindingIndexFunction · 0.90
bindingUpdatedFunction · 0.90
addLViewToLContainerFunction · 0.90
shouldAddViewToDomFunction · 0.90
removeDehydratedViewsFunction · 0.90

Tested by

no test coverage detected