mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
on Refactor... #4
This commit is contained in:
30
browser/main/Mixins/Helper.js
Normal file
30
browser/main/Mixins/Helper.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function deleteItemFromTargetArray (item, targetArray) {
|
||||
targetArray.some(function (_item, index) {
|
||||
if (_item.id === item.id) {
|
||||
targetArray.splice(index, 1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
return targetArray
|
||||
}
|
||||
|
||||
function updateItemToTargetArray (item, targetArray) {
|
||||
var isNew = !targetArray.some(function (_item, index) {
|
||||
if (_item.id === item.id) {
|
||||
targetArray.splice(index, 1, item)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (isNew) targetArray.push(item)
|
||||
|
||||
return targetArray
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
deleteItemFromTargetArray: deleteItemFromTargetArray,
|
||||
updateItemToTargetArray: updateItemToTargetArray
|
||||
}
|
||||
Reference in New Issue
Block a user