From 7b96397e3bfa43a393ca84439069290bc4c8a5c8 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Tue, 7 Feb 2023 13:04:03 +0000 Subject: [PATCH] feat: use klona instead of lodash.clonedeep (#3073) Resolves: https://kolaente.dev/vikunja/frontend/issues/3032 Co-authored-by: Dominik Pschenitschni Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/3073 Co-authored-by: Dominik Pschenitschni Co-committed-by: Dominik Pschenitschni --- package.json | 2 +- pnpm-lock.yaml | 13 +++++++------ src/stores/kanban.ts | 4 ++-- src/views/list/ListKanban.vue | 6 +++--- src/views/list/helpers/useGanttTaskList.ts | 4 ++-- src/views/tasks/TaskDetailView.vue | 4 ++-- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 867640ff0..5da85ddce 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "focus-within": "3.0.2", "highlight.js": "11.7.0", "is-touch-device": "1.0.1", - "lodash.clonedeep": "4.5.0", + "klona": "2.0.6", "lodash.debounce": "4.0.8", "marked": "4.2.12", "minimist": "1.2.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3147db269..4931330a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,7 +63,7 @@ specifiers: highlight.js: 11.7.0 histoire: 0.13.0 is-touch-device: 1.0.1 - lodash.clonedeep: 4.5.0 + klona: 2.0.6 lodash.debounce: 4.0.8 marked: 4.2.12 minimist: 1.2.7 @@ -129,7 +129,7 @@ dependencies: focus-within: 3.0.2 highlight.js: 11.7.0 is-touch-device: 1.0.1 - lodash.clonedeep: 4.5.0 + klona: 2.0.6 lodash.debounce: 4.0.8 marked: 4.2.12 minimist: 1.2.7 @@ -10037,6 +10037,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /klona/2.0.6: + resolution: {integrity: sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==} + engines: {node: '>= 8'} + dev: false + /kuler/2.0.0: resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==} dev: true @@ -10216,10 +10221,6 @@ packages: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} dev: true - /lodash.clonedeep/4.5.0: - resolution: {integrity: sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=} - dev: false - /lodash.debounce/4.0.8: resolution: {integrity: sha1-gteb/zCmfEAF/9XiUVMArZyk168=} diff --git a/src/stores/kanban.ts b/src/stores/kanban.ts index a5d89f359..da7c2e482 100644 --- a/src/stores/kanban.ts +++ b/src/stores/kanban.ts @@ -1,6 +1,6 @@ import {computed, readonly, ref} from 'vue' import {defineStore, acceptHMRUpdate} from 'pinia' -import cloneDeep from 'lodash.clonedeep' +import {klona} from 'klona/lite' import {findById, findIndexById} from '@/helpers/utils' import {i18n} from '@/i18n' @@ -333,7 +333,7 @@ export const useKanbanStore = defineStore('kanban', () => { const cancel = setModuleLoading(setIsLoading) const bucketIndex = findIndexById(buckets.value, updatedBucketData.id) - const oldBucket = cloneDeep(buckets.value[bucketIndex]) + const oldBucket = klona(buckets.value[bucketIndex]) const updatedBucket = { ...oldBucket, diff --git a/src/views/list/ListKanban.vue b/src/views/list/ListKanban.vue index dacae8f40..a23dcb104 100644 --- a/src/views/list/ListKanban.vue +++ b/src/views/list/ListKanban.vue @@ -227,7 +227,7 @@ import {computed, nextTick, ref, watch, type PropType} from 'vue' import {useI18n} from 'vue-i18n' import draggable from 'zhyswan-vuedraggable' -import cloneDeep from 'lodash.clonedeep' +import {klona} from 'klona/lite' import {RIGHTS as Rights} from '@/constants/rights' import BucketModel from '@/models/bucket' @@ -419,7 +419,7 @@ async function updateTaskPosition(e) { const taskAfter = newBucket.tasks[newTaskIndex + 1] ?? null taskUpdating.value[task.id] = true - const newTask = cloneDeep(task) // cloning the task to avoid pinia store manipulation + const newTask = klona(task) // cloning the task to avoid pinia store manipulation newTask.bucketId = newBucket.id newTask.kanbanPosition = calculateItemPosition( taskBefore !== null ? taskBefore.kanbanPosition : null, @@ -432,7 +432,7 @@ async function updateTaskPosition(e) { // Make sure the first and second task don't both get position 0 assigned if(newTaskIndex === 0 && taskAfter !== null && taskAfter.kanbanPosition === 0) { const taskAfterAfter = newBucket.tasks[newTaskIndex + 2] ?? null - const newTaskAfter = cloneDeep(taskAfter) // cloning the task to avoid pinia store manipulation + const newTaskAfter = klona(taskAfter) // cloning the task to avoid pinia store manipulation newTaskAfter.bucketId = newBucket.id newTaskAfter.kanbanPosition = calculateItemPosition( 0, diff --git a/src/views/list/helpers/useGanttTaskList.ts b/src/views/list/helpers/useGanttTaskList.ts index df4080066..36856a040 100644 --- a/src/views/list/helpers/useGanttTaskList.ts +++ b/src/views/list/helpers/useGanttTaskList.ts @@ -1,5 +1,5 @@ import {computed, ref, shallowReactive, watch, type Ref} from 'vue' -import cloneDeep from 'lodash.clonedeep' +import {klona} from 'klona/lite' import type {Filters} from '@/composables/useRouteFilters' import type {ITask, ITaskPartialWithId} from '@/modelTypes/ITask' @@ -64,7 +64,7 @@ export function useGanttTaskList( } async function updateTask(task: ITaskPartialWithId) { - const oldTask = cloneDeep(tasks.value.get(task.id)) + const oldTask = klona(tasks.value.get(task.id)) if (!oldTask) return diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index eac5cb90c..68c2a269b 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -449,7 +449,7 @@ import {ref, reactive, toRef, shallowReactive, computed, watch, nextTick, type P import {useRouter, type RouteLocation} from 'vue-router' import {useI18n} from 'vue-i18n' import {unrefElement} from '@vueuse/core' -import cloneDeep from 'lodash.clonedeep' +import {klona} from 'klona/lite' import TaskService from '@/services/task' import TaskModel, {TASK_DEFAULT_COLOR} from '@/models/task' @@ -703,7 +703,7 @@ async function saveTask(args?: { undoCallback, } = { ...{ - task: cloneDeep(task), + task: klona(task), }, ...args, }