Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3fd7da

Browse files
committed
🎨 MultiListCollection arrangement of methods
1 parent cc62bff commit c3fd7da

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

lib/multi-list-collection.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,57 @@ export default class MultiListCollection {
1616
this.updateSelections()
1717
}
1818

19+
clearSelectedItems () {
20+
this.selectedItems = new Set()
21+
}
22+
23+
clearSelectedKeys () {
24+
this.selectedKeys = new Set()
25+
}
26+
27+
getSelectedItems () {
28+
return this.selectedItems
29+
}
30+
31+
getSelectedKeys () {
32+
return this.selectedKeys
33+
}
34+
35+
getItemsForKey (key) {
36+
return this.list.getItemsForKey(key)
37+
}
38+
1939
getLastSelectedListKey () {
2040
return this.list.getSelectedListKey()
2141
}
2242

43+
selectNextList ({wrap, addToExisting} = {}) {
44+
this.list.selectNextList({wrap})
45+
this.updateSelections({addToExisting})
46+
}
47+
48+
selectPreviousList ({wrap, addToExisting} = {}) {
49+
this.list.selectPreviousList({wrap})
50+
this.updateSelections({addToExisting})
51+
}
52+
53+
selectNextItem ({addToExisting, stopAtBounds} = {}) {
54+
this.list.selectNextItem({stopAtBounds})
55+
this.updateSelections({addToExisting})
56+
}
57+
58+
selectPreviousItem ({addToExisting, stopAtBounds} = {}) {
59+
this.list.selectPreviousItem({stopAtBounds})
60+
this.updateSelections({addToExisting})
61+
}
62+
63+
updateSelections ({addToExisting} = {}) {
64+
const selectedKey = this.list.getSelectedListKey()
65+
const selectedItem = this.list.getSelectedItem()
66+
this.selectItems(selectedItem ? [selectedItem] : [], {addToExisting, suppressCallback: true})
67+
this.selectKeys(selectedKey ? [selectedKey] : [], {addToExisting, suppressCallback: true})
68+
}
69+
2370
selectItems (items, {addToExisting, suppressCallback} = {}) {
2471
if (!addToExisting) this.clearSelectedItems()
2572
items.forEach(item => this.selectedItems.add(item))
@@ -42,22 +89,6 @@ export default class MultiListCollection {
4289
this.selectItems([this.list.getItemsForKey(key)[0]], {addToExisting})
4390
}
4491

45-
clearSelectedItems () {
46-
this.selectedItems = new Set()
47-
}
48-
49-
clearSelectedKeys () {
50-
this.selectedKeys = new Set()
51-
}
52-
53-
getSelectedItems () {
54-
return this.selectedItems
55-
}
56-
57-
getSelectedKeys () {
58-
return this.selectedKeys
59-
}
60-
6192
selectItemsAndKeysInRange (endPoint1, endPoint2, addToExisting) {
6293
if (!addToExisting) {
6394
this.clearSelectedItems()
@@ -108,35 +139,4 @@ export default class MultiListCollection {
108139
}
109140
}
110141
}
111-
112-
selectNextList ({wrap, addToExisting} = {}) {
113-
this.list.selectNextList({wrap})
114-
this.updateSelections({addToExisting})
115-
}
116-
117-
selectPreviousList ({wrap, addToExisting} = {}) {
118-
this.list.selectPreviousList({wrap})
119-
this.updateSelections({addToExisting})
120-
}
121-
122-
updateSelections ({addToExisting} = {}) {
123-
const selectedKey = this.list.getSelectedListKey()
124-
const selectedItem = this.list.getSelectedItem()
125-
this.selectItems(selectedItem ? [selectedItem] : [], {addToExisting, suppressCallback: true})
126-
this.selectKeys(selectedKey ? [selectedKey] : [], {addToExisting, suppressCallback: true})
127-
}
128-
129-
selectNextItem ({addToExisting, stopAtBounds} = {}) {
130-
this.list.selectNextItem({stopAtBounds})
131-
this.updateSelections({addToExisting})
132-
}
133-
134-
selectPreviousItem ({addToExisting, stopAtBounds} = {}) {
135-
this.list.selectPreviousItem({stopAtBounds})
136-
this.updateSelections({addToExisting})
137-
}
138-
139-
getItemsForKey (key) {
140-
return this.list.getItemsForKey(key)
141-
}
142142
}

0 commit comments

Comments
 (0)