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

Skip to content

Commit 258557f

Browse files
committed
🎨 multiListCollection instance variable
1 parent c3fd7da commit 258557f

File tree

4 files changed

+89
-89
lines changed

4 files changed

+89
-89
lines changed

lib/views/file-patch-view.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class FilePatchView {
1616
const hunkLineLists = props.hunks.map(hunk => {
1717
return { key: hunk, items: hunk.getLines().filter(l => l.isChanged()) }
1818
})
19-
this.list = new MultiListCollection(hunkLineLists)
19+
this.multiListCollection = new MultiListCollection(hunkLineLists)
2020
this.setInitialSelection()
2121
this.enableSelections = this.enableSelections.bind(this)
2222
this.disableSelections = this.disableSelections.bind(this)
@@ -47,37 +47,37 @@ export default class FilePatchView {
4747

4848
setInitialSelection () {
4949
if (this.selectionMode === 'hunk') {
50-
this.list.selectAllItemsForKey(this.list.getLastSelectedListKey())
50+
this.multiListCollection.selectAllItemsForKey(this.multiListCollection.getLastSelectedListKey())
5151
}
5252
}
5353

5454
getSelectedLines () {
55-
return this.list.getSelectedItems()
55+
return this.multiListCollection.getSelectedItems()
5656
}
5757

5858
getSelectedHunks () {
59-
return this.list.getSelectedKeys()
59+
return this.multiListCollection.getSelectedKeys()
6060
}
6161

6262
focusNextHunk ({wrap, addToExisting} = {}) {
63-
this.list.selectNextList({wrap, addToExisting})
63+
this.multiListCollection.selectNextList({wrap, addToExisting})
6464
this.selectLinesBasedOnSelectionMode({addToExisting})
6565
return etch.update(this)
6666
}
6767

6868
focusPreviousHunk ({wrap, addToExisting} = {}) {
69-
this.list.selectPreviousList({wrap, addToExisting})
69+
this.multiListCollection.selectPreviousList({wrap, addToExisting})
7070
this.selectLinesBasedOnSelectionMode({addToExisting})
7171
return etch.update(this)
7272
}
7373

7474
focusPreviousHunkLine ({addToExisting} = {}) {
75-
this.list.selectPreviousItem({addToExisting})
75+
this.multiListCollection.selectPreviousItem({addToExisting})
7676
return etch.update(this)
7777
}
7878

7979
focusNextHunkLine ({addToExisting} = {}) {
80-
this.list.selectNextItem({addToExisting})
80+
this.multiListCollection.selectNextItem({addToExisting})
8181
return etch.update(this)
8282
}
8383

@@ -86,7 +86,7 @@ export default class FilePatchView {
8686
const hunkLineLists = props.hunks.map(hunk => {
8787
return { key: hunk, items: hunk.getLines().filter(l => l.isChanged()) }
8888
})
89-
this.list.updateLists(hunkLineLists)
89+
this.multiListCollection.updateLists(hunkLineLists)
9090
this.setInitialSelection()
9191
return etch.update(this)
9292
}
@@ -103,8 +103,8 @@ export default class FilePatchView {
103103
onmouseup={() => this.disableSelections()}
104104
onmousedown={() => this.enableSelections()}>
105105
{this.props.hunks.map((hunk) => {
106-
const isSelected = this.list.getSelectedKeys().has(hunk)
107-
const selectedLines = isSelected ? this.list.getSelectedItems() : EMPTY_SET
106+
const isSelected = this.multiListCollection.getSelectedKeys().has(hunk)
107+
const selectedLines = isSelected ? this.multiListCollection.getSelectedItems() : EMPTY_SET
108108
return (
109109
<HunkView
110110
hunk={hunk}
@@ -134,11 +134,11 @@ export default class FilePatchView {
134134
}
135135

136136
selectLinesBasedOnSelectionMode ({addToExisting} = {}) {
137-
const hunk = this.list.getLastSelectedListKey()
137+
const hunk = this.multiListCollection.getLastSelectedListKey()
138138
if (this.selectionMode === 'hunk') {
139-
this.list.selectAllItemsForKey(hunk, addToExisting)
139+
this.multiListCollection.selectAllItemsForKey(hunk, addToExisting)
140140
} else {
141-
this.list.selectFirstItemForKey(hunk)
141+
this.multiListCollection.selectFirstItemForKey(hunk)
142142
}
143143
}
144144

@@ -153,25 +153,25 @@ export default class FilePatchView {
153153
}
154154

155155
focusHunk (hunk) {
156-
this.list.selectKeys([hunk])
156+
this.multiListCollection.selectKeys([hunk])
157157
this.setInitialSelection()
158158
}
159159

160160
selectLineForHunk (hunk, selectedLine) {
161161
if (!this.tail) this.tail = {key: hunk, item: selectedLine}
162162
this.head = {key: hunk, item: selectedLine}
163163
if (this.selectionMode === 'hunk') {
164-
this.list.selectAllItemsForKey(hunk, true)
164+
this.multiListCollection.selectAllItemsForKey(hunk, true)
165165
} else {
166-
this.list.selectItemsAndKeysInRange(this.tail, this.head)
166+
this.multiListCollection.selectItemsAndKeysInRange(this.tail, this.head)
167167
}
168168
return etch.update(this)
169169
}
170170

171171
stageSelectedLines () {
172172
this.disableSelections()
173173
const selectedLines = this.getSelectedLines()
174-
this.list.clearSelectedItems()
174+
this.multiListCollection.clearSelectedItems()
175175
if (this.props.stagingStatus === 'unstaged') {
176176
return this.props.stageLines(selectedLines)
177177
} else if (this.props.stagingStatus === 'staged') {

lib/views/staging-view.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class StagingView {
3434
this.disableSelections = this.disableSelections.bind(this)
3535
this.renderFilePatchListItem = this.renderFilePatchListItem.bind(this)
3636
this.renderMergeConflictListItem = this.renderMergeConflictListItem.bind(this)
37-
this.multiList = new MultiListCollection([
37+
this.multiListCollection = new MultiListCollection([
3838
{ key: ListTypes.UNSTAGED, items: this.props.unstagedChanges },
3939
{ key: ListTypes.CONFLICTS, items: this.props.mergeConflicts || [] },
4040
{ key: ListTypes.STAGED, items: this.props.stagedChanges }
@@ -56,7 +56,7 @@ export default class StagingView {
5656

5757
update (props) {
5858
this.props = props
59-
this.multiList.updateLists([
59+
this.multiListCollection.updateLists([
6060
{ key: ListTypes.UNSTAGED, items: this.props.unstagedChanges },
6161
{ key: ListTypes.CONFLICTS, items: this.props.mergeConflicts || [] },
6262
{ key: ListTypes.STAGED, items: this.props.stagedChanges }
@@ -65,7 +65,7 @@ export default class StagingView {
6565
}
6666

6767
enableSelections () {
68-
this.validItems = new Set(this.multiList.getItemsForKey(this.getSelectedListKey()))
68+
this.validItems = new Set(this.multiListCollection.getItemsForKey(this.getSelectedListKey()))
6969
this.selectionEnabled = true
7070
return etch.update(this)
7171
}
@@ -78,26 +78,26 @@ export default class StagingView {
7878
}
7979

8080
selectList (listKey) {
81-
if (this.multiList.getItemsForKey(listKey).length) {
82-
this.multiList.selectKeys([listKey])
81+
if (this.multiListCollection.getItemsForKey(listKey).length) {
82+
this.multiListCollection.selectKeys([listKey])
8383
}
8484
this.enableSelections()
8585
return etch.update(this)
8686
}
8787

8888
focusNextList () {
89-
this.multiList.selectNextList({wrap: true})
89+
this.multiListCollection.selectNextList({wrap: true})
9090
return etch.update(this)
9191
}
9292

9393
focusPreviousList () {
94-
this.multiList.selectPreviousList({wrap: true})
94+
this.multiListCollection.selectPreviousList({wrap: true})
9595
return etch.update(this)
9696
}
9797

9898
confirmSelectedItems () {
9999
this.disableSelections()
100-
const itemPaths = Array.from(this.multiList.getSelectedItems()).map(item => item.getPath())
100+
const itemPaths = Array.from(this.getSelectedItems()).map(item => item.getPath())
101101
const listKey = this.getSelectedListKey()
102102
if (listKey === ListTypes.STAGED) {
103103
return this.props.unstageFiles(itemPaths)
@@ -107,7 +107,11 @@ export default class StagingView {
107107
}
108108

109109
getSelectedListKey () {
110-
return this.multiList.getLastSelectedListKey()
110+
return this.multiListCollection.getLastSelectedListKey()
111+
}
112+
113+
getSelectedItems () {
114+
return this.multiListCollection.getSelectedItems()
111115
}
112116

113117
stageFilePatch (filePatch) {
@@ -119,12 +123,12 @@ export default class StagingView {
119123
}
120124

121125
selectPreviousFilePatch (options = {}) {
122-
this.multiList.selectPreviousItem(options)
126+
this.multiListCollection.selectPreviousItem(options)
123127
return etch.update(this)
124128
}
125129

126130
selectNextFilePatch (options = {}) {
127-
this.multiList.selectNextItem(options)
131+
this.multiListCollection.selectNextItem(options)
128132
return etch.update(this)
129133
}
130134

@@ -133,7 +137,7 @@ export default class StagingView {
133137
const selectedList = this.getSelectedListKey()
134138
if (!this.tail) this.tail = {key: selectedList, item}
135139
this.head = {key: selectedList, item}
136-
this.multiList.selectItemsAndKeysInRange(this.tail, this.head)
140+
this.multiListCollection.selectItemsAndKeysInRange(this.tail, this.head)
137141
return etch.update(this)
138142
}
139143

@@ -149,7 +153,7 @@ export default class StagingView {
149153

150154
buildDebugData () {
151155
const getPath = (fp) => fp ? fp.getNewPath() : '<none>'
152-
const multiListData = this.multiList.toObject()
156+
const multiListData = this.multiListCollection.toObject()
153157
return {
154158
...multiListData,
155159
lists: multiListData.lists.map(list => list.map(getPath))
@@ -183,8 +187,8 @@ export default class StagingView {
183187
className='git-FilePatchListView'
184188
ref='mergeConflictListView'
185189
didConfirmItem={this.stageFilePatch}
186-
items={this.multiList.getItemsForKey(ListTypes.CONFLICTS)}
187-
selectedItems={this.multiList.getSelectedItems()}
190+
items={this.multiListCollection.getItemsForKey(ListTypes.CONFLICTS)}
191+
selectedItems={this.getSelectedItems()}
188192
renderItem={this.renderMergeConflictListItem}
189193
/>
190194
</div>
@@ -202,12 +206,12 @@ export default class StagingView {
202206
className='git-FilePatchListView'
203207
ref='unstagedChangesView'
204208
didConfirmItem={this.stageFilePatch}
205-
items={this.multiList.getItemsForKey(ListTypes.UNSTAGED)}
206-
selectedItems={this.multiList.getSelectedItems()}
209+
items={this.multiListCollection.getItemsForKey(ListTypes.UNSTAGED)}
210+
selectedItems={this.getSelectedItems()}
207211
renderItem={this.renderFilePatchListItem}
208212
/>
209213
</div>
210-
{ this.multiList.getItemsForKey(ListTypes.CONFLICTS).length ? mergeConflictsView : <noscript /> }
214+
{ this.multiListCollection.getItemsForKey(ListTypes.CONFLICTS).length ? mergeConflictsView : <noscript /> }
211215
<div className={`git-StagingView-group git-StagedChanges ${stagedClassName}`}
212216
onmousedown={() => {
213217
this.selectList(ListTypes.STAGED)
@@ -217,8 +221,8 @@ export default class StagingView {
217221
className='git-FilePatchListView'
218222
ref='stagedChangesView'
219223
didConfirmItem={this.unstageFilePatch}
220-
items={this.multiList.getItemsForKey(ListTypes.STAGED)}
221-
selectedItems={this.multiList.getSelectedItems()}
224+
items={this.multiListCollection.getItemsForKey(ListTypes.STAGED)}
225+
selectedItems={this.getSelectedItems()}
222226
renderItem={this.renderFilePatchListItem}
223227
/>
224228
</div>

test/multi-list-collection.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,55 @@ import MultiListCollection from '../lib/multi-list-collection'
55
describe('MultiListCollection', () => {
66
describe('selectItemsAndKeysInRange(endPoint1, endPoint2)', () => {
77
it('takes endpoints ({key, item}) and returns an array of items between those points', () => {
8-
const ml = new MultiListCollection([
8+
const mlc = new MultiListCollection([
99
{ key: 'list1', items: ['a', 'b', 'c'] },
1010
{ key: 'list2', items: ['d', 'e'] },
1111
{ key: 'list3', items: ['f', 'g', 'h'] }
1212
])
1313

14-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'list1', item: 'c'})
15-
assert.deepEqual([...ml.getSelectedItems()], ['b', 'c'])
16-
assert.deepEqual([...ml.getSelectedKeys()], ['list1'])
14+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'list1', item: 'c'})
15+
assert.deepEqual([...mlc.getSelectedItems()], ['b', 'c'])
16+
assert.deepEqual([...mlc.getSelectedKeys()], ['list1'])
1717

1818
// endpoints can be specified in any order
19-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list1', item: 'b'})
20-
assert.deepEqual([...ml.getSelectedItems()], ['b', 'c'])
21-
assert.deepEqual([...ml.getSelectedKeys()], ['list1'])
19+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list1', item: 'b'})
20+
assert.deepEqual([...mlc.getSelectedItems()], ['b', 'c'])
21+
assert.deepEqual([...mlc.getSelectedKeys()], ['list1'])
2222

2323
// endpoints can be in different lists
24-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list3', item: 'g'})
25-
assert.deepEqual([...ml.getSelectedItems()], ['c', 'd', 'e', 'f', 'g'])
26-
assert.deepEqual([...ml.getSelectedKeys()], ['list1', 'list2', 'list3'])
24+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list3', item: 'g'})
25+
assert.deepEqual([...mlc.getSelectedItems()], ['c', 'd', 'e', 'f', 'g'])
26+
assert.deepEqual([...mlc.getSelectedKeys()], ['list1', 'list2', 'list3'])
2727

28-
ml.selectItemsAndKeysInRange({key: 'list3', item: 'g'}, {key: 'list1', item: 'c'})
29-
assert.deepEqual([...ml.getSelectedItems()], ['c', 'd', 'e', 'f', 'g'])
30-
assert.deepEqual([...ml.getSelectedKeys()], ['list1', 'list2', 'list3'])
28+
mlc.selectItemsAndKeysInRange({key: 'list3', item: 'g'}, {key: 'list1', item: 'c'})
29+
assert.deepEqual([...mlc.getSelectedItems()], ['c', 'd', 'e', 'f', 'g'])
30+
assert.deepEqual([...mlc.getSelectedKeys()], ['list1', 'list2', 'list3'])
3131

3232
// endpoints can be the same
33-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list1', item: 'c'})
34-
assert.deepEqual([...ml.getSelectedItems()], ['c'])
35-
assert.deepEqual([...ml.getSelectedKeys()], ['list1'])
33+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'c'}, {key: 'list1', item: 'c'})
34+
assert.deepEqual([...mlc.getSelectedItems()], ['c'])
35+
assert.deepEqual([...mlc.getSelectedKeys()], ['list1'])
3636
})
3737

3838
it('throws error when keys or items aren\'t found', () => {
39-
const ml = new MultiListCollection([
39+
const mlc = new MultiListCollection([
4040
{ key: 'list1', items: ['a', 'b', 'c'] }
4141
])
4242

4343
assert.throws(() => {
44-
ml.selectItemsAndKeysInRange({key: 'non-existent-key', item: 'b'}, {key: 'list1', item: 'c'})
44+
mlc.selectItemsAndKeysInRange({key: 'non-existent-key', item: 'b'}, {key: 'list1', item: 'c'})
4545
}, 'key "non-existent-key" not found')
4646

4747
assert.throws(() => {
48-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'non-existent-key', item: 'c'})
48+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'non-existent-key', item: 'c'})
4949
}, 'key "non-existent-key" not found')
5050

5151
assert.throws(() => {
52-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'x'}, {key: 'list1', item: 'c'})
52+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'x'}, {key: 'list1', item: 'c'})
5353
}, 'item "x" not found')
5454

5555
assert.throws(() => {
56-
ml.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'list1', item: 'x'})
56+
mlc.selectItemsAndKeysInRange({key: 'list1', item: 'b'}, {key: 'list1', item: 'x'})
5757
}, 'item "x" not found')
5858
})
5959
})

0 commit comments

Comments
 (0)