1 | import CollectionEventType from './CollectionEventType';
|
2 | import { EventsKey } from './events';
|
3 | import BaseEvent from './events/Event';
|
4 | import BaseObject, { ObjectEvent } from './Object';
|
5 |
|
6 | export interface Options {
|
7 | unique?: boolean | undefined;
|
8 | }
|
9 | export default class Collection<T> extends BaseObject {
|
10 | constructor(opt_array?: T[], opt_options?: Options);
|
11 | /**
|
12 | * Remove all elements from the collection.
|
13 | */
|
14 | clear(): void;
|
15 | /**
|
16 | * Add elements to the collection. This pushes each item in the provided array
|
17 | * to the end of the collection.
|
18 | */
|
19 | extend(arr: T[]): Collection<T>;
|
20 | /**
|
21 | * Iterate over each element, calling the provided callback.
|
22 | */
|
23 | forEach(f: (p0: T, p1: number, p2: T[]) => any): void;
|
24 | /**
|
25 | * Get a reference to the underlying Array object. Warning: if the array
|
26 | * is mutated, no events will be dispatched by the collection, and the
|
27 | * collection's "length" property won't be in sync with the actual length
|
28 | * of the array.
|
29 | */
|
30 | getArray(): T[];
|
31 | /**
|
32 | * Get the length of this collection.
|
33 | */
|
34 | getLength(): number;
|
35 | /**
|
36 | * Insert an element at the provided index.
|
37 | */
|
38 | insertAt(index: number, elem: T): void;
|
39 | /**
|
40 | * Get the element at the provided index.
|
41 | */
|
42 | item(index: number): T;
|
43 | /**
|
44 | * Remove the last element of the collection and return it.
|
45 | * Return undefined if the collection is empty.
|
46 | */
|
47 | pop(): T | undefined;
|
48 | /**
|
49 | * Insert the provided element at the end of the collection.
|
50 | */
|
51 | push(elem: T): number;
|
52 | /**
|
53 | * Remove the first occurrence of an element from the collection.
|
54 | */
|
55 | remove(elem: T): T | undefined;
|
56 | /**
|
57 | * Remove the element at the provided index and return it.
|
58 | * Return undefined if the collection does not contain this index.
|
59 | */
|
60 | removeAt(index: number): T | undefined;
|
61 | /**
|
62 | * Set the element at the provided index.
|
63 | */
|
64 | setAt(index: number, elem: T): void;
|
65 | on(type: string | string[], listener: (p0: any) => any): EventsKey | EventsKey[];
|
66 | once(type: string | string[], listener: (p0: any) => any): EventsKey | EventsKey[];
|
67 | un(type: string | string[], listener: (p0: any) => any): void;
|
68 | on(type: 'add', listener: (evt: CollectionEvent<T>) => void): EventsKey;
|
69 | once(type: 'add', listener: (evt: CollectionEvent<T>) => void): EventsKey;
|
70 | un(type: 'add', listener: (evt: CollectionEvent<T>) => void): void;
|
71 | on(type: 'change', listener: (evt: BaseEvent) => void): EventsKey;
|
72 | once(type: 'change', listener: (evt: BaseEvent) => void): EventsKey;
|
73 | un(type: 'change', listener: (evt: BaseEvent) => void): void;
|
74 | on(type: 'change:length', listener: (evt: ObjectEvent) => void): EventsKey;
|
75 | once(type: 'change:length', listener: (evt: ObjectEvent) => void): EventsKey;
|
76 | un(type: 'change:length', listener: (evt: ObjectEvent) => void): void;
|
77 | on(type: 'error', listener: (evt: BaseEvent) => void): EventsKey;
|
78 | once(type: 'error', listener: (evt: BaseEvent) => void): EventsKey;
|
79 | un(type: 'error', listener: (evt: BaseEvent) => void): void;
|
80 | on(type: 'propertychange', listener: (evt: ObjectEvent) => void): EventsKey;
|
81 | once(type: 'propertychange', listener: (evt: ObjectEvent) => void): EventsKey;
|
82 | un(type: 'propertychange', listener: (evt: ObjectEvent) => void): void;
|
83 | on(type: 'remove', listener: (evt: CollectionEvent<T>) => void): EventsKey;
|
84 | once(type: 'remove', listener: (evt: CollectionEvent<T>) => void): EventsKey;
|
85 | un(type: 'remove', listener: (evt: CollectionEvent<T>) => void): void;
|
86 | }
|
87 | export class CollectionEvent<T> extends BaseEvent {
|
88 | constructor(type: CollectionEventType, opt_element?: T, opt_index?: number);
|
89 | /**
|
90 | * The element that is added to or removed from the collection.
|
91 | */
|
92 | element: T;
|
93 | /**
|
94 | * The index of the added or removed element.
|
95 | */
|
96 | index: number;
|
97 | }
|