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