@ux-aspects/ux-aspects
Version:
Open source user interface framework for building modern, responsive, mobile big data applications
71 lines (70 loc) • 3.18 kB
TypeScript
import { DoCheck, OnDestroy, OnInit, TrackByFunction } from '@angular/core';
import * as i0 from "@angular/core";
/**
* This implementation is inspired by the CDK virtual for:
* https://github.com/angular/material2/blob/master/src/cdk/scrolling/virtual-for-of.ts
* However the CDK requires a container component which limits use in places such
* as fixed header tables, so this is a more generic implementation that does not
* require a parent element but instead uses an attribute on the parent container instead
*/
export declare class VirtualForDirective<T> implements OnInit, DoCheck, OnDestroy {
/** A reference to the container element where we will insert elements. */
private readonly _viewContainerRef;
/** The template for all items */
private readonly _templateRef;
/** Gets the set of Angular differs for detecting changes. */
private readonly _differs;
/** Get the renderer to perform DOM manipulation */
private readonly _renderer;
private readonly _changeDetector;
/** A service to share values between the container and child elements */
private readonly _virtualScroll;
/** Store the list of items to display */
set uxVirtualForOf(dataset: T[]);
/** Provide a trackBy function to optimize rendering */
uxVirtualForTrackBy: TrackByFunction<T> | undefined;
/** The instance of the differ we create */
private _differ;
/** Keep a local reference to the dataset */
private _dataset;
/** Store the currently rendered range */
private _renderedRange;
/** Store a list of all the currently rendered items */
private _renderedItems;
/** Indicate whether we need to perform a view update */
private _isDirty;
/** Store a cache of recently disposed views for reuse */
private readonly _templateCache;
/** Limit the size of the cache as it can use a lot of memory */
private readonly _cacheSize;
/** Unsubscribe from all observables */
private readonly _onDestroy;
constructor();
ngOnInit(): void;
ngDoCheck(): void;
ngOnDestroy(): void;
/** If an itemSize is not specified we need to calculate it */
getHeight(context: T, length: number): number;
/** Determine if the range has changed (performance optimization) */
private isRangeSame;
private onRangeChange;
/** Determine which items have changed */
private getChanges;
/** Insert, move and remove any items within the view */
private applyChanges;
updateContexts(): void;
private createView;
private defaultTrackBy;
static ɵfac: i0.ɵɵFactoryDeclaration<VirtualForDirective<any>, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<VirtualForDirective<any>, "[uxVirtualFor][uxVirtualForOf]", never, { "uxVirtualForOf": { "alias": "uxVirtualForOf"; "required": false; }; "uxVirtualForTrackBy": { "alias": "uxVirtualForTrackBy"; "required": false; }; }, {}, never, never, false, never>;
}
/** We want to supply the same properties as `ngFor` */
export interface VirtualForOfContext<T> {
$implicit: T;
index: number;
count: number;
first: boolean;
last: boolean;
even: boolean;
odd: boolean;
}