wgge 1.1.1 → 1.1.3
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
CHANGED
|
@@ -34,6 +34,14 @@ export default class Collection extends NodeWithEvents {
|
|
|
34
34
|
return this.insert(element, 0);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
removeInternal(index, element) {
|
|
38
|
+
if (index < 0 || !element) return false;
|
|
39
|
+
this.items.splice(index, 1);
|
|
40
|
+
this.triggerEvent('remove', element);
|
|
41
|
+
this.triggerEvent('change');
|
|
42
|
+
return element;
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
remove(element) {
|
|
38
46
|
const index = this.items.indexOf(element);
|
|
39
47
|
return this.removeInternal(index, element);
|
|
@@ -46,18 +54,6 @@ export default class Collection extends NodeWithEvents {
|
|
|
46
54
|
return false;
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
removeInternal(index, element) {
|
|
50
|
-
if (index >= 0) {
|
|
51
|
-
this.items.splice(index, 1);
|
|
52
|
-
}
|
|
53
|
-
if (element) {
|
|
54
|
-
this.triggerEvent('remove', element);
|
|
55
|
-
this.triggerEvent('change');
|
|
56
|
-
return element;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
57
|
reset() {
|
|
62
58
|
while (this.removeFirst()) {
|
|
63
59
|
}
|
|
@@ -85,18 +81,12 @@ export default class Collection extends NodeWithEvents {
|
|
|
85
81
|
|
|
86
82
|
swap(childA, childB) {
|
|
87
83
|
const indexA = this.items.indexOf(childA);
|
|
88
|
-
if (indexA < 0) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.removeInternal(indexA, childA);
|
|
92
|
-
|
|
93
84
|
const indexB = this.items.indexOf(childB);
|
|
94
|
-
if (indexB < 0) {
|
|
95
|
-
this.insert(childA, indexA);
|
|
85
|
+
if (indexA < 0 || indexB < 0) {
|
|
96
86
|
return;
|
|
97
87
|
}
|
|
88
|
+
this.removeInternal(indexA, childA);
|
|
98
89
|
this.removeInternal(indexB, childB);
|
|
99
|
-
|
|
100
90
|
this.insert(childA, indexB);
|
|
101
91
|
this.insert(childB, indexA);
|
|
102
92
|
}
|
|
@@ -35,10 +35,8 @@ export default class EventManager {
|
|
|
35
35
|
if (!this.handlers[eventName]) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
const handlers = this.handlers[eventName];
|
|
39
|
-
handlers.forEach((item) =>
|
|
40
|
-
item(param);
|
|
41
|
-
});
|
|
38
|
+
const handlers = [...this.handlers[eventName]];
|
|
39
|
+
handlers.forEach((item) => item(param));
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
}
|