wgge 2.0.22 → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/Collection.js +10 -0
- package/package.json +1 -1
package/core/Collection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import NodeWithEvents from "./model/event/NodeWithEvents";
|
|
2
|
+
import ArrayHelper from "./helper/ArrayHelper";
|
|
2
3
|
|
|
3
4
|
export default class Collection extends NodeWithEvents {
|
|
4
5
|
|
|
@@ -23,6 +24,10 @@ export default class Collection extends NodeWithEvents {
|
|
|
23
24
|
return element;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
get(index) {
|
|
28
|
+
return this.items[index];
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
insert(element, index) {
|
|
27
32
|
this.items.splice(index, 0, element);
|
|
28
33
|
this.triggerEvent('insert', element);
|
|
@@ -128,6 +133,11 @@ export default class Collection extends NodeWithEvents {
|
|
|
128
133
|
return this.items.sort(sortFunc);
|
|
129
134
|
}
|
|
130
135
|
|
|
136
|
+
random() {
|
|
137
|
+
if (this.isEmpty()) return undefined;
|
|
138
|
+
return this.get(ArrayHelper.randomIndex(this.count()-1));
|
|
139
|
+
}
|
|
140
|
+
|
|
131
141
|
addOnRemoveListener(listener) {
|
|
132
142
|
this.addEventListener('remove', listener);
|
|
133
143
|
}
|