1+ /**
2+ * @classdesc
3+ * Events emitted by {@link module:ol/Collection~Collection} instances are instances of this
4+ * type.
5+ * @template T
6+ */
7+ export class CollectionEvent < T > extends Event {
8+ /**
9+ * @param {import("./CollectionEventType.js").default } type Type.
10+ * @param {T } element Element.
11+ * @param {number } index The index of the added or removed element.
12+ */
13+ constructor ( type : any , element : T , index : number ) ;
14+ /**
15+ * The element that is added to or removed from the collection.
16+ * @type {T }
17+ * @api
18+ */
19+ element : T ;
20+ /**
21+ * The index of the added or removed element.
22+ * @type {number }
23+ * @api
24+ */
25+ index : number ;
26+ }
27+ export default Collection ;
28+ /**
29+ * *
30+ */
31+ export type CollectionOnSignature < T , Return > = import ( "./Observable" ) . OnSignature < import ( "./Observable" ) . EventTypes , import ( "./events/Event.js" ) . default , Return > & import ( "./Observable" ) . OnSignature < import ( "./ObjectEventType" ) . Types | "change:length" , import ( "./Object" ) . ObjectEvent , Return > & import ( "./Observable" ) . OnSignature < "add" | "remove" , CollectionEvent < T > , Return > & import ( "./Observable" ) . CombinedOnSignature < import ( "./Observable" ) . EventTypes | import ( "./ObjectEventType" ) . Types | "change:length" | "add" | "remove" , Return > ;
32+ export type Options = {
33+ /**
34+ * Disallow the same item from being added to
35+ * the collection twice.
36+ */
37+ unique ?: boolean | undefined ;
38+ } ;
39+ import Event from './events/Event.js' ;
40+ /***
41+ * @template T
42+ * @template Return
43+ * @typedef {import("./Observable").OnSignature<import("./Observable").EventTypes, import("./events/Event.js").default, Return> &
44+ * import("./Observable").OnSignature<import("./ObjectEventType").Types|'change:length', import("./Object").ObjectEvent, Return> &
45+ * import("./Observable").OnSignature<'add'|'remove', CollectionEvent<T>, Return> &
46+ * import("./Observable").CombinedOnSignature<import("./Observable").EventTypes|import("./ObjectEventType").Types|
47+ * 'change:length'|'add'|'remove',Return>} CollectionOnSignature
48+ */
49+ /**
50+ * @typedef {Object } Options
51+ * @property {boolean } [unique=false] Disallow the same item from being added to
52+ * the collection twice.
53+ */
54+ /**
55+ * @classdesc
56+ * An expanded version of standard JS Array, adding convenience methods for
57+ * manipulation. Add and remove changes to the Collection trigger a Collection
58+ * event. Note that this does not cover changes to the objects _within_ the
59+ * Collection; they trigger events on the appropriate object, not on the
60+ * Collection as a whole.
61+ *
62+ * @fires CollectionEvent
63+ *
64+ * @template T
65+ * @api
66+ */
67+ declare class Collection < T > extends BaseObject {
68+ /**
69+ * @param {Array<T> } [array] Array.
70+ * @param {Options } [options] Collection options.
71+ */
72+ constructor ( array ?: Array < T > , options ?: Options ) ;
73+ /***
74+ * @type {CollectionOnSignature<T, import("./events").EventsKey> }
75+ */
76+ on : CollectionOnSignature < T , import ( "./events" ) . EventsKey > ;
77+ /***
78+ * @type {CollectionOnSignature<T, import("./events").EventsKey> }
79+ */
80+ once : CollectionOnSignature < T , import ( "./events" ) . EventsKey > ;
81+ /***
82+ * @type {CollectionOnSignature<T, void> }
83+ */
84+ un : CollectionOnSignature < T , void > ;
85+ /**
86+ * @private
87+ * @type {boolean }
88+ */
89+ private unique_ ;
90+ /**
91+ * @private
92+ * @type {!Array<T> }
93+ */
94+ private array_ ;
95+ /**
96+ * Remove all elements from the collection.
97+ * @api
98+ */
99+ clear ( ) : void ;
100+ /**
101+ * Add elements to the collection. This pushes each item in the provided array
102+ * to the end of the collection.
103+ * @param {!Array<T> } arr Array.
104+ * @return {Collection<T> } This collection.
105+ * @api
106+ */
107+ extend ( arr : Array < T > ) : Collection < T > ;
108+ /**
109+ * Iterate over each element, calling the provided callback.
110+ * @param {function(T, number, Array<T>): * } f The function to call
111+ * for every element. This function takes 3 arguments (the element, the
112+ * index and the array). The return value is ignored.
113+ * @api
114+ */
115+ forEach ( f : ( arg0 : T , arg1 : number , arg2 : Array < T > ) => any ) : void ;
116+ /**
117+ * Get a reference to the underlying Array object. Warning: if the array
118+ * is mutated, no events will be dispatched by the collection, and the
119+ * collection's "length" property won't be in sync with the actual length
120+ * of the array.
121+ * @return {!Array<T> } Array.
122+ * @api
123+ */
124+ getArray ( ) : Array < T > ;
125+ /**
126+ * Get the element at the provided index.
127+ * @param {number } index Index.
128+ * @return {T } Element.
129+ * @api
130+ */
131+ item ( index : number ) : T ;
132+ /**
133+ * Get the length of this collection.
134+ * @return {number } The length of the array.
135+ * @observable
136+ * @api
137+ */
138+ getLength ( ) : number ;
139+ /**
140+ * Insert an element at the provided index.
141+ * @param {number } index Index.
142+ * @param {T } elem Element.
143+ * @api
144+ */
145+ insertAt ( index : number , elem : T ) : void ;
146+ /**
147+ * Remove the last element of the collection and return it.
148+ * Return `undefined` if the collection is empty.
149+ * @return {T|undefined } Element.
150+ * @api
151+ */
152+ pop ( ) : T | undefined ;
153+ /**
154+ * Insert the provided element at the end of the collection.
155+ * @param {T } elem Element.
156+ * @return {number } New length of the collection.
157+ * @api
158+ */
159+ push ( elem : T ) : number ;
160+ /**
161+ * Remove the first occurrence of an element from the collection.
162+ * @param {T } elem Element.
163+ * @return {T|undefined } The removed element or undefined if none found.
164+ * @api
165+ */
166+ remove ( elem : T ) : T | undefined ;
167+ /**
168+ * Remove the element at the provided index and return it.
169+ * Return `undefined` if the collection does not contain this index.
170+ * @param {number } index Index.
171+ * @return {T|undefined } Value.
172+ * @api
173+ */
174+ removeAt ( index : number ) : T | undefined ;
175+ /**
176+ * Set the element at the provided index.
177+ * @param {number } index Index.
178+ * @param {T } elem Element.
179+ * @api
180+ */
181+ setAt ( index : number , elem : T ) : void ;
182+ /**
183+ * @private
184+ */
185+ private updateLength_ ;
186+ /**
187+ * @private
188+ * @param {T } elem Element.
189+ * @param {number } [except] Optional index to ignore.
190+ */
191+ private assertUnique_ ;
192+ }
193+ import BaseObject from './Object.js' ;
194+ //# sourceMappingURL=Collection.d.ts.map
0 commit comments