1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Refactor tag removing methods (duplicated code)

This commit is contained in:
bimlas
2018-05-18 15:18:28 +02:00
parent 52b3068330
commit a6af5de3e1

View File

@@ -44,16 +44,9 @@ class TagSelect extends React.Component {
}
removeLastTag () {
let { value } = this.props
value = _.isArray(value)
? value.slice()
: []
value.pop()
value = _.uniq(value)
this.value = value
this.props.onChange()
this.removeTagByCallback((value) => {
value.pop()
})
}
reset () {
@@ -96,12 +89,18 @@ class TagSelect extends React.Component {
}
handleTagRemoveButtonClick (tag) {
this.removeTagByCallback((value, tag) => {
value.splice(value.indexOf(tag), 1)
}, tag)
}
removeTagByCallback (callback, tag = null) {
let { value } = this.props
value = _.isArray(value)
? value.slice()
: []
value.splice(value.indexOf(tag), 1)
callback(value, tag)
value = _.uniq(value)
this.value = value