UNPKG

2.22 kBTypeScriptView Raw
1import { Observable, EventData } from '../observable';
2import { ChangedData } from '../observable-array';
3/**
4 * Event args for "itemsLoading" event.
5 */
6export interface ItemsLoading extends EventData {
7 /**
8 * Start index.
9 */
10 index: number;
11 /**
12 * Number of items to load.
13 */
14 count: number;
15}
16/**
17 * Advanced array like class that helps loading items on demand.
18 */
19export declare class VirtualArray<T> extends Observable {
20 /**
21 * String value used when hooking to change event.
22 */
23 static changeEvent: string;
24 /**
25 * String value used when hooking to itemsLoading event.
26 */
27 static itemsLoadingEvent: string;
28 private _requestedIndexes;
29 private _loadedIndexes;
30 private _length;
31 private _cache;
32 constructor(length?: number);
33 /**
34 * Gets or sets length for the virtual array.
35 */
36 get length(): number;
37 set length(value: number);
38 /**
39 * Gets or sets load size for the virtual array.
40 */
41 private _loadSize;
42 get loadSize(): number;
43 set loadSize(value: number);
44 getItem(index: number): T;
45 setItem(index: number, value: T): void;
46 /**
47 * Loads items from an array starting at index.
48 */
49 load(index: number, items: T[]): void;
50 private requestItems;
51}
52export interface VirtualArray<T> {
53 /**
54 * A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
55 * @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
56 * @param callback - Callback function which will be executed when event is raised.
57 * @param thisArg - An optional parameter which will be used as `this` context for callback execution.
58 */
59 on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
60 /**
61 * Raised when still not loaded items are requested.
62 */
63 on(event: 'itemsLoading', callback: (args: ItemsLoading) => void, thisArg?: any): void;
64 /**
65 * Raised when a change occurs.
66 */
67 on(event: 'change', callback: (args: ChangedData<T>) => void, thisArg?: any): void;
68}