Skip to content

Commit a6af5de

Browse files
committed
Refactor tag removing methods (duplicated code)
1 parent 52b3068 commit a6af5de

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

browser/main/Detail/TagSelect.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,9 @@ class TagSelect extends React.Component {
4444
}
4545

4646
removeLastTag () {
47-
let { value } = this.props
48-
49-
value = _.isArray(value)
50-
? value.slice()
51-
: []
52-
value.pop()
53-
value = _.uniq(value)
54-
55-
this.value = value
56-
this.props.onChange()
47+
this.removeTagByCallback((value) => {
48+
value.pop()
49+
})
5750
}
5851

5952
reset () {
@@ -96,12 +89,18 @@ class TagSelect extends React.Component {
9689
}
9790

9891
handleTagRemoveButtonClick (tag) {
92+
this.removeTagByCallback((value, tag) => {
93+
value.splice(value.indexOf(tag), 1)
94+
}, tag)
95+
}
96+
97+
removeTagByCallback (callback, tag = null) {
9998
let { value } = this.props
10099

101100
value = _.isArray(value)
102101
? value.slice()
103102
: []
104-
value.splice(value.indexOf(tag), 1)
103+
callback(value, tag)
105104
value = _.uniq(value)
106105

107106
this.value = value

0 commit comments

Comments
 (0)