fix: directly set arrays, objects and delete directly

Not needed since vue3 uses proxies
This commit is contained in:
Dominik Pschenitschni 2021-08-19 21:35:38 +02:00
parent 2b20f328cb
commit db49b9b532
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
33 changed files with 104 additions and 113 deletions

View File

@ -187,7 +187,7 @@ export default {
.then(namespaces => {
namespaces.forEach(n => {
if (typeof this.listsVisible[n.id] === 'undefined') {
this.$set(this.listsVisible, n.id, true)
this.listsVisible[n.id] = true
}
})
})
@ -217,7 +217,7 @@ export default {
}
},
toggleLists(namespaceId) {
this.$set(this.listsVisible, namespaceId, !this.listsVisible[namespaceId] ?? false)
this.listsVisible[namespaceId] = !this.listsVisible[namespaceId] ?? false
},
updateActiveLists(namespace, activeLists) {
// this is a bit hacky: since we do have to filter out the archived items from the list
@ -242,7 +242,7 @@ export default {
const list = listsActive[e.newIndex]
const listBefore = listsActive[e.newIndex - 1] ?? null
const listAfter = listsActive[e.newIndex + 1] ?? null
this.$set(this.listUpdating, list.id, true)
this.listUpdating[list.id] = true
const position = calculateItemPosition(listBefore !== null ? listBefore.position : null, listAfter !== null ? listAfter.position : null)
@ -255,7 +255,7 @@ export default {
this.$message.error(e)
})
.finally(() => {
this.$set(this.listUpdating, list.id, false)
this.listUpdating[list.id] = false
})
},
},

View File

@ -284,7 +284,7 @@ export default {
this.closeSearchResults()
},
setSelectedObject(object, resetOnly = false) {
this.$set(this, 'internalValue', object)
this.internalValue = object
// We assume we're getting an array when multiple is enabled and can therefore leave the query
// value etc as it is

View File

@ -344,11 +344,11 @@ export default {
this.params.filter_by.forEach((f, i) => {
if (f === filterName && this.params.filter_comparator[i] === 'greater_equals') {
foundStart = true
this.$set(this.params.filter_value, i, formatISO(new Date(parts[0])))
this.params.filter_value[i] = formatISO(new Date(parts[0]))
}
if (f === filterName && this.params.filter_comparator[i] === 'less_equals') {
foundEnd = true
this.$set(this.params.filter_value, i, formatISO(new Date(parts[1])))
this.params.filter_value[i] = formatISO(new Date(parts[1]))
}
})
@ -406,7 +406,7 @@ export default {
this.params.filter_by.forEach((f, i) => {
if (f === filterName) {
found = true
this.$set(this.params.filter_value, i, this.filters[variableName])
this.params.filter_value[i] = this.filters[variableName]
}
})
@ -466,7 +466,7 @@ export default {
}
})
if (foundDone === false) {
this.$set(this.filters, 'done', true)
this.filters.done = true
}
},
prepareRelatedObjectFilter(kind, filterName = null, servicePrefix = null) {
@ -482,7 +482,7 @@ export default {
if (typeof this.filters[filterName] !== 'undefined' && this.filters[filterName] !== '') {
this[`${servicePrefix}Service`].getAll({}, {s: this.filters[filterName]})
.then(r => {
this.$set(this, kind, r)
this[kind] = r
})
.catch(e => this.$message.error(e))
}
@ -523,7 +523,7 @@ export default {
this.setDateFilter('reminders')
},
clear(kind) {
this.$set(this, `found${kind}`, [])
this[`found${kind}`] = []
},
find(kind, query) {
@ -534,9 +534,9 @@ export default {
this[`${kind}Service`].getAll({}, {s: query})
.then(response => {
// Filter the results to not include users who are already assigneid
this.$set(this, `found${kind}`, differenceWith(response, this[kind], (first, second) => {
this[`found${kind}`] = differenceWith(response, this[kind], (first, second) => {
return first.id === second.id
}))
})
})
.catch(e => {
this.$message.error(e)
@ -564,7 +564,7 @@ export default {
ids.push(u.id)
})
this.$set(this.filters, filterName, ids.join(','))
this.filters[filterName] = ids.join(',')
this.setSingleValueFilter(filterName, filterName, '', 'in')
},
findLabels(query) {
@ -599,7 +599,7 @@ export default {
labelIDs.push(u.id)
})
this.$set(this.filters, 'labels', labelIDs.join(','))
this.filters.labels = labelIDs.join(',')
this.setSingleValueFilter('labels', 'labels', '', 'in')
},
},

View File

@ -66,7 +66,7 @@ export default {
const listService = new ListService()
listService.background(this.list)
.then(b => {
this.$set(this, 'background', b)
this.background = b
})
.catch(e => {
this.$message.error(e)

View File

@ -96,7 +96,7 @@ export default {
loadNotifications() {
this.notificationService.getAll()
.then(r => {
this.$set(this, 'allNotifications', r)
this.allNotifications = r
})
.catch(e => {
this.$message.error(e)
@ -135,7 +135,7 @@ export default {
n.read = true
this.notificationService.update(n)
.then(r => {
this.$set(this.allNotifications, index, r)
this.allNotifications[index] = r
})
.catch(e => this.$message.error(e))
}

View File

@ -298,7 +298,7 @@ export default {
return t
})
this.$set(this, 'foundTasks', r)
this.foundTasks = r
})
}, 150)
},
@ -329,7 +329,7 @@ export default {
t.title = t.name
return t
})
this.$set(this, 'foundTeams', r)
this.foundTeams = r
})
}, 150)
},

View File

@ -276,9 +276,9 @@ export default {
this.stuffService
.getAll(this.stuffModel)
.then((r) => {
this.$set(this, 'sharables', r)
this.sharables = r
r.forEach((s) =>
this.$set(this.selectedRight, s.id, s.right),
this.selectedRight[s.id] = s.right,
)
})
.catch((e) => {
@ -362,7 +362,7 @@ export default {
(this.sharables[i].id === this.stuffModel.teamId &&
this.shareType === 'team')
) {
this.$set(this.sharables[i], 'right', r.right)
this.sharables[i].right = r.right
}
}
this.$message.success({message: this.$t('list.share.userTeam.updatedSuccess', {type: this.shareTypeName})})
@ -373,21 +373,21 @@ export default {
},
find(query) {
if (query === '') {
this.$set(this, 'found', [])
this.clearAll()
return
}
this.searchService
.getAll({}, {s: query})
.then((response) => {
this.$set(this, 'found', response)
this.found = response
})
.catch((e) => {
this.$message.error(e)
})
},
clearAll() {
this.$set(this, 'found', [])
this.found = []
},
},
}

View File

@ -143,7 +143,7 @@ export default {
this.taskService
.update(this.taskEditTask)
.then((r) => {
this.$set(this, 'taskEditTask', r)
this.taskEditTask = r
this.initTaskFields()
this.$message.success({message: this.$t('task.detail.updateSuccess')})
})

View File

@ -299,15 +299,15 @@ export default {
this.fullWidth += this.dayWidth
}
console.debug('prepareGanttDays; years:', years)
this.$set(this, 'days', years)
this.days = years
},
parseTasks() {
this.setDates()
this.loadTasks()
},
loadTasks() {
this.$set(this, 'theTasks', [])
this.$set(this, 'tasksWithoutDates', [])
this.theTasks = []
this.tasksWithoutDates = []
const getAllTasks = (page = 1) => {
return this.taskCollectionService
@ -392,7 +392,7 @@ export default {
// prevent it from containing outdated Data in the first place.
for (const tt in this.theTasks) {
if (this.theTasks[tt].id === this.taskDragged.id) {
this.$set(this, 'taskDragged', this.theTasks[tt])
this.taskDragged = this.theTasks[tt]
break
}
}
@ -422,11 +422,7 @@ export default {
} else {
for (const tt in this.theTasks) {
if (this.theTasks[tt].id === r.id) {
this.$set(
this.theTasks,
tt,
this.addGantAttributes(r),
)
this.theTasks[tt] = this.addGantAttributes(r)
break
}
}

View File

@ -229,7 +229,7 @@ export default {
this.taskCommentService
.getAll({taskId: this.taskId})
.then(r => {
this.$set(this, 'comments', r)
this.comments = r
this.makeActions()
})
.catch((e) => {
@ -286,7 +286,7 @@ export default {
.then((r) => {
for (const c in this.comments) {
if (this.comments[c].id === this.commentEdit.id) {
this.$set(this.comments, c, r)
this.comments[c] = r
}
}
this.saved = this.commentEdit.id
@ -322,12 +322,12 @@ export default {
makeActions() {
if (this.canWrite) {
this.comments.forEach((c) => {
this.$set(this.actions, c.id, [
this.actions[c.id] = [
{
action: () => this.toggleDelete(c.id),
title: this.$t('misc.delete'),
},
])
]
})
}
},

View File

@ -111,16 +111,16 @@ export default {
this.listUserService.getAll({listId: this.listId}, {s: query})
.then(response => {
// Filter the results to not include users who are already assigned
this.$set(this, 'foundUsers', differenceWith(response, this.assignees, (first, second) => {
this.foundUsers = differenceWith(response, this.assignees, (first, second) => {
return first.id === second.id
}))
})
})
.catch(e => {
this.$message.error(e)
})
},
clearAllFoundUsers() {
this.$set(this, 'foundUsers', [])
this.foundUsers = []
},
focus() {
this.$refs.multiselect.focus()

View File

@ -56,14 +56,14 @@ export default {
this.listSerivce.getAll({}, {s: query})
.then(response => {
this.$set(this, 'foundLists', response)
this.foundLists = response
})
.catch(e => {
this.$message.error(e)
})
},
clearAll() {
this.$set(this, 'foundLists', [])
this.foundLists = []
},
select(list) {
this.list = list

View File

@ -188,7 +188,7 @@ export default {
findTasks(query) {
this.taskService.getAll({}, {s: query})
.then(response => {
this.$set(this, 'foundTasks', response)
this.foundTasks = response
})
.catch(e => {
this.$message.error(e)
@ -203,7 +203,7 @@ export default {
this.taskRelationService.create(rel)
.then(() => {
if (!this.relatedTasks[this.newTaskRelationKind]) {
this.$set(this.relatedTasks, this.newTaskRelationKind, [])
this.relatedTasks[this.newTaskRelationKind] = []
}
this.relatedTasks[this.newTaskRelationKind].push(this.newTaskRelationTask)
this.newTaskRelationTask = null

View File

@ -1,5 +1,3 @@
import Vue from 'vue'
import {findIndexById} from '@/helpers/find'
export default {
@ -10,7 +8,7 @@ export default {
mutations: {
set(state, attachments) {
console.debug('Set attachments', attachments)
Vue.set(state, 'attachments', attachments)
state.attachments = attachments
},
add(state, attachment) {
console.debug('Add attachement', attachment)

View File

@ -1,5 +1,3 @@
import Vue from 'vue'
import {CONFIG} from '../mutation-types'
import {HTTPFactory} from '@/http-common'
import {objectToCamelCase} from '@/helpers/case'
@ -58,7 +56,7 @@ export default {
state.auth.local.enabled = auth.local.enabled
state.auth.openidConnect.enabled = auth.openidConnect.enabled
state.auth.openidConnect.redirectUrl = auth.openidConnect.redirectUrl
Vue.set(state.auth.openidConnect, 'providers', auth.openidConnect.providers)
state.auth.openidConnect.providers = auth.openidConnect.providers
},
},
actions: {

View File

@ -1,4 +1,3 @@
import Vue from 'vue'
import cloneDeep from 'lodash/cloneDeep'
import BucketService from '../../services/bucket'
@ -34,8 +33,8 @@ export default {
setBuckets(state, buckets) {
state.buckets = buckets
buckets.forEach(b => {
Vue.set(state.taskPagesPerBucket, b.id, 1)
Vue.set(state.allTasksLoadedForBucket, b.id, false)
state.taskPagesPerBucket[b.id] = 1
state.allTasksLoadedForBucket[b.id] = false
})
},
addBucket(state, bucket) {
@ -51,18 +50,18 @@ export default {
setBucketById(state, bucket) {
for (const b in state.buckets) {
if (state.buckets[b].id === bucket.id) {
Vue.set(state.buckets, b, bucket)
state.buckets[b] = bucket
return
}
}
},
setBucketByIndex(state, {bucketIndex, bucket}) {
Vue.set(state.buckets, bucketIndex, bucket)
state.buckets[bucketIndex] = bucket
},
setTaskInBucketByIndex(state, {bucketIndex, taskIndex, task}) {
const bucket = state.buckets[bucketIndex]
bucket.tasks[taskIndex] = task
Vue.set(state.buckets, bucketIndex, bucket)
state.buckets[bucketIndex] = bucket
},
setTaskInBucket(state, task) {
// If this gets invoked without any tasks actually loaded, we can save the hassle of finding the task
@ -83,7 +82,8 @@ export default {
addTaskToBucketAndSort(state, task)
}
Vue.set(state.buckets, b, bucket)
state.buckets[b] = bucket
found = true
return
}
@ -129,7 +129,7 @@ export default {
if (state.buckets[b].tasks[t].id === task.id) {
const bucket = state.buckets[b]
bucket.tasks.splice(t, 1)
Vue.set(state.buckets, b, bucket)
state.buckets[b] = bucket
return
}
}
@ -138,13 +138,14 @@ export default {
}
},
setBucketLoading(state, {bucketId, loading}) {
Vue.set(state.bucketLoading, bucketId, loading)
state.bucketLoading[bucketId] = loading
},
setTasksLoadedForBucketPage(state, {bucketId, page}) {
Vue.set(state.taskPagesPerBucket, bucketId, page)
state.taskPagesPerBucket[bucketId] = page
},
setAllTasksLoadedForBucket(state, bucketId) {
Vue.set(state.allTasksLoadedForBucket, bucketId, true)
state.allTasksLoadedForBucket[bucketId] = true
},
},
getters: {

View File

@ -1,5 +1,4 @@
import LabelService from '@/services/label'
import Vue from 'vue'
import {setLoading} from '@/store/helper'
export default {
@ -12,14 +11,14 @@ export default {
mutations: {
setLabels(state, labels) {
labels.forEach(l => {
Vue.set(state.labels, l.id, l)
state.labels[l.id] = l
})
},
setLabel(state, label) {
Vue.set(state.labels, label.id, label)
state.labels[label.id] = label
},
removeLabelById(state, label) {
Vue.delete(state.labels, label.id)
delete state.labels[label.id]
},
setLoaded(state, loaded) {
state.loaded = loaded

View File

@ -1,4 +1,3 @@
import Vue from 'vue'
import ListService from '@/services/list'
import {setLoading} from '@/store/helper'
import {removeListFromHistory} from '@/modules/listHistory.ts'
@ -11,11 +10,11 @@ export default {
state: () => ({}),
mutations: {
setList(state, list) {
Vue.set(state, list.id, list)
state[list.id] = list
},
setLists(state, lists) {
lists.forEach(l => {
Vue.set(state, l.id, l)
state[l.id] = l
})
},
removeListById(state, list) {

View File

@ -1,5 +1,3 @@
import Vue from 'vue'
import NamespaceService from '../../services/namespace'
import {setLoading} from '@/store/helper'
@ -19,11 +17,13 @@ export default {
return
}
// FIXME: direct manipulation of the prop
// might not be a problem since this is happening in the mutation
if (!namespace.lists || namespace.lists.length === 0) {
namespace.lists = state.namespaces[namespaceIndex].lists
}
Vue.set(state.namespaces, namespaceIndex, namespace)
state.namespaces[namespaceIndex] = namespace
},
setListInNamespaceById(state, list) {
for (const n in state.namespaces) {
@ -34,7 +34,7 @@ export default {
if (state.namespaces[n].lists[l].id === list.id) {
const namespace = state.namespaces[n]
namespace.lists[l] = list
Vue.set(state.namespaces, n, namespace)
state.namespaces[n] = namespace
return
}
}

View File

@ -142,7 +142,7 @@ export default {
const list = new ListModel(listData)
this.listService.get(list)
.then(r => {
this.$set(this, 'list', r)
this.list = r
this.$store.commit(CURRENT_LIST, r)
this.setTitle(this.getListTitle(r))
})

View File

@ -104,8 +104,8 @@ export default {
return
}
// This is an extra method to reset a few things when searching to not break loading more photos.
this.$set(this, 'backgroundSearchResult', [])
this.$set(this, 'backgroundThumbs', {})
this.backgroundSearchResult = []
this.backgroundThumbs = {}
this.searchBackgrounds()
},
searchBackgrounds(page = 1) {
@ -124,7 +124,7 @@ export default {
r.forEach(b => {
this.backgroundService.thumb(b)
.then(t => {
this.$set(this.backgroundThumbs, b.id, t)
this.backgroundThumbs[b.id] = t
})
})
})

View File

@ -106,7 +106,7 @@ export default {
this.listService.get(list)
.then(r => {
this.$set(this, 'list', r)
this.list = r
this.$store.commit(CURRENT_LIST, r)
this.setTitle(this.$t('list.edit.title', {list: this.list.title}))
})

View File

@ -61,7 +61,7 @@ export default {
this.listService.get(list)
.then(r => {
this.$set(this, 'list', r)
this.list = r
this.$store.commit(CURRENT_LIST, r)
// This will trigger the dynamic loading of components once we actually have all the data to pass to them
this.manageTeamsComponent = 'userTeam'

View File

@ -398,20 +398,20 @@ export default {
this.$message.error(e)
})
.finally(() => {
this.$set(this.taskUpdating, task.id, false)
this.taskUpdating[task.id] = false
this.oneTaskUpdating = false
})
},
toggleShowNewTaskInput(bucket) {
this.$set(this.showNewTaskInput, bucket, !this.showNewTaskInput[bucket])
this.showNewTaskInput[bucket] = !this.showNewTaskInput[bucket]
},
addTaskToBucket(bucketId) {
if (this.newTaskText === '') {
this.$set(this.newTaskError, bucketId, true)
this.newTaskError[bucketId] = true
return
}
this.$set(this.newTaskError, bucketId, false)
this.newTaskError[bucketId] = false
this.createNewTask(this.newTaskText, bucketId)
.then(r => {
@ -557,7 +557,7 @@ export default {
})
},
collapseBucket(bucket) {
this.$set(this.collapsedBuckets, bucket.id, true)
this.collapsedBuckets[bucket.id] = true
saveCollapsedBucketState(this.$route.params.listId, this.collapsedBuckets)
},
unCollapseBucket(bucket) {
@ -565,7 +565,7 @@ export default {
return
}
this.$set(this.collapsedBuckets, bucket.id, false)
this.collapsedBuckets[bucket.id] = false
saveCollapsedBucketState(this.$route.params.listId, this.collapsedBuckets)
},
},

View File

@ -279,7 +279,7 @@ export default {
updateTasks(updatedTask) {
for (const t in this.tasks) {
if (this.tasks[t].id === updatedTask.id) {
this.$set(this.tasks, t, updatedTask)
this.tasks[t] = updatedTask
break
}
}
@ -299,7 +299,7 @@ export default {
this.$store.dispatch('tasks/update', newTask)
.then(r => {
this.$set(this.tasks, e.newIndex, r)
this.tasks[e.newIndex] = r
})
.catch(e => {
this.$message.error(e)

View File

@ -239,16 +239,16 @@ export default {
created() {
const savedShowColumns = localStorage.getItem('tableViewColumns')
if (savedShowColumns !== null) {
this.$set(this, 'activeColumns', JSON.parse(savedShowColumns))
this.activeColumns = JSON.parse(savedShowColumns)
}
const savedSortBy = localStorage.getItem('tableViewSortBy')
if (savedSortBy !== null) {
this.$set(this, 'sortBy', JSON.parse(savedSortBy))
this.sortBy = JSON.parse(savedSortBy)
}
this.$set(this.params, 'filter_by', [])
this.$set(this.params, 'filter_value', [])
this.$set(this.params, 'filter_comparator', [])
this.params.filter_by = []
this.params.filter_value = []
this.params.filter_comparator = []
this.initTasks(1)
@ -286,11 +286,11 @@ export default {
sort(property) {
const order = this.sortBy[property]
if (typeof order === 'undefined' || order === 'none') {
this.$set(this.sortBy, property, 'desc')
this.sortBy[property] = 'desc'
} else if (order === 'desc') {
this.$set(this.sortBy, property, 'asc')
this.sortBy[property] = 'asc'
} else {
this.$delete(this.sortBy, property)
delete this.sortBy[property]
}
this.initTasks(this.currentPage, this.searchTerm)
// Save the order to be able to retrieve them later

View File

@ -110,7 +110,7 @@ export default {
const namespace = new NamespaceModel({id: this.$route.params.id})
this.namespaceService.get(namespace)
.then(r => {
this.$set(this, 'namespace', r)
this.namespace = r
// This will trigger the dynamic loading of components once we actually have all the data to pass to them
this.manageTeamsComponent = 'manageSharing'
this.manageUsersComponent = 'manageSharing'

View File

@ -61,7 +61,7 @@ export default {
const namespace = new NamespaceModel({id: this.$route.params.id})
this.namespaceService.get(namespace)
.then(r => {
this.$set(this, 'namespace', r)
this.namespace = r
// This will trigger the dynamic loading of components once we actually have all the data to pass to them
this.manageTeamsComponent = 'manageSharing'
this.manageUsersComponent = 'manageSharing'

View File

@ -206,7 +206,7 @@ export default {
})
const tasks = r.filter(t => t.dueDate !== null).concat(r.filter(t => t.dueDate === null))
this.$set(this, 'tasks', tasks)
this.tasks = tasks
})
.catch(e => {
this.$message.error(e)
@ -215,7 +215,7 @@ export default {
updateTasks(updatedTask) {
for (const t in this.tasks) {
if (this.tasks[t].id === updatedTask.id) {
this.$set(this.tasks, t, updatedTask)
this.tasks[t] = updatedTask
// Move the task to the end of the done tasks if it is now done
if (updatedTask.done) {
this.tasks.splice(t, 1)

View File

@ -561,7 +561,7 @@ export default {
this.taskId = Number(this.$route.params.id)
this.taskService.get({id: this.taskId})
.then(r => {
this.$set(this, 'task', r)
this.task = r
this.$store.commit('attachments/set', r.attachments)
this.taskColor = this.task.hexColor
this.setActiveFields()

View File

@ -232,7 +232,7 @@ export default {
this.teamService
.get(this.team)
.then((response) => {
this.$set(this, 'team', response)
this.team = response
this.title = this.$t('team.edit.title', {team: this.team.name})
this.setTitle(this.title)
})
@ -305,7 +305,7 @@ export default {
.then((r) => {
for (const tm in this.team.members) {
if (this.team.members[tm].id === member.id) {
this.$set(this.team.members[tm], 'admin', r.admin)
this.team.members[tm].admin = r.admin
break
}
}
@ -321,21 +321,21 @@ export default {
},
findUser(query) {
if (query === '') {
this.$set(this, 'foundUsers', [])
this.clearAll()
return
}
this.userService
.getAll({}, {s: query})
.then((response) => {
this.$set(this, 'foundUsers', response)
this.foundUsers = response
})
.catch((e) => {
this.$message.error(e)
})
},
clearAll() {
this.$set(this, 'foundUsers', [])
this.foundUsers = []
},
},
}

View File

@ -46,7 +46,7 @@ export default {
loadTeams() {
this.teamService.getAll()
.then(response => {
this.$set(this, 'teams', response)
this.teams = response
})
.catch(e => {
this.$message.error(e)

View File

@ -409,7 +409,7 @@ export default {
}
this.totpService.get()
.then(r => {
this.$set(this, 'totp', r)
this.totp = r
this.totpSetQrCode()
})
.catch(e => {
@ -433,7 +433,7 @@ export default {
this.totpService.enroll()
.then(r => {
this.totpEnrolled = true
this.$set(this, 'totp', r)
this.totp = r
this.totpSetQrCode()
})
.catch(e => this.$message.error(e))
@ -441,7 +441,7 @@ export default {
totpConfirm() {
this.totpService.enable({passcode: this.totpConfirmPasscode})
.then(() => {
this.$set(this.totp, 'enabled', true)
this.totp.enabled = true
this.$message.success({message: this.$t('user.settings.totp.confirmSuccess')})
})
.catch(e => this.$message.error(e))
@ -450,7 +450,7 @@ export default {
this.totpService.disable({password: this.totpDisablePassword})
.then(() => {
this.totpEnrolled = false
this.$set(this, 'totp', new TotpModel())
this.totp = new TotpModel()
this.$message.success({message: this.$t('user.settings.totp.disableSuccess')})
})
.catch(e => this.$message.error(e))