-
Notifications
You must be signed in to change notification settings - Fork 984
/
Copy pathindex.js
53 lines (44 loc) · 956 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export default class Manager {
refs = {};
add(collection, ref) {
if (!this.refs[collection]) {
this.refs[collection] = [];
}
this.refs[collection].push(ref);
}
remove(collection, ref) {
const index = this.getIndex(collection, ref);
if (index !== -1) {
this.refs[collection].splice(index, 1);
}
}
isActive() {
return this.active;
}
getActive() {
return this.refs[this.active.collection].find(
// eslint-disable-next-line eqeqeq
({node}) => node.sortableInfo.index == this.active.index,
);
}
getIndex(collection, ref) {
return this.refs[collection].indexOf(ref);
}
getOrderedRefs(collection = this.active.collection) {
return this.refs[collection].sort(sortByIndex);
}
}
function sortByIndex(
{
node: {
sortableInfo: {index: index1},
},
},
{
node: {
sortableInfo: {index: index2},
},
},
) {
return index1 - index2;
}