| 81 | selector: '[cdkVirtualFor][cdkVirtualForOf]', |
| 82 | }) |
| 83 | export class CdkVirtualForOf<T> |
| 84 | implements CdkVirtualScrollRepeater<T>, CollectionViewer, DoCheck, OnDestroy |
| 85 | { |
| 86 | private _viewContainerRef = inject(ViewContainerRef); |
| 87 | private _template = inject<TemplateRef<CdkVirtualForOfContext<T>>>(TemplateRef); |
| 88 | private _differs = inject(IterableDiffers); |
| 89 | private _viewRepeater = new _RecycleViewRepeaterStrategy<T, T, CdkVirtualForOfContext<T>>(); |
| 90 | private _viewport = inject(CDK_VIRTUAL_SCROLL_VIEWPORT, {skipSelf: true}); |
| 91 | |
| 92 | /** Emits when the rendered view of the data changes. */ |
| 93 | readonly viewChange = new Subject<ListRange>(); |
| 94 | |
| 95 | /** Subject that emits when a new DataSource instance is given. */ |
| 96 | private readonly _dataSourceChanges = new Subject<DataSource<T>>(); |
| 97 | |
| 98 | /** The DataSource to display. */ |
| 99 | @Input() |
| 100 | get cdkVirtualForOf(): DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined { |
| 101 | return this._cdkVirtualForOf; |
| 102 | } |
| 103 | set cdkVirtualForOf(value: DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined) { |
| 104 | this._cdkVirtualForOf = value; |
| 105 | if (isDataSource(value)) { |
| 106 | this._dataSourceChanges.next(value); |
| 107 | } else { |
| 108 | // If value is an an NgIterable, convert it to an array. |
| 109 | this._dataSourceChanges.next( |
| 110 | new ArrayDataSource<T>(isObservable(value) ? value : Array.from(value || [])), |
| 111 | ); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | _cdkVirtualForOf: DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined; |
| 116 | |
| 117 | /** |
| 118 | * The `TrackByFunction` to use for tracking changes. The `TrackByFunction` takes the index and |
| 119 | * the item and produces a value to be used as the item's identity when tracking changes. |
| 120 | */ |
| 121 | @Input() |
| 122 | get cdkVirtualForTrackBy(): TrackByFunction<T> | undefined { |
| 123 | return this._cdkVirtualForTrackBy; |
| 124 | } |
| 125 | set cdkVirtualForTrackBy(fn: TrackByFunction<T> | undefined) { |
| 126 | this._needsUpdate = true; |
| 127 | this._cdkVirtualForTrackBy = fn |
| 128 | ? (index, item) => fn(index + (this._renderedRange ? this._renderedRange.start : 0), item) |
| 129 | : undefined; |
| 130 | } |
| 131 | private _cdkVirtualForTrackBy: TrackByFunction<T> | undefined; |
| 132 | |
| 133 | /** The template used to stamp out new elements. */ |
| 134 | @Input() |
| 135 | set cdkVirtualForTemplate(value: TemplateRef<CdkVirtualForOfContext<T>>) { |
| 136 | if (value) { |
| 137 | this._needsUpdate = true; |
| 138 | this._template = value; |
| 139 | } |
| 140 | } |
nothing calls this directly
no test coverage detected