diff --git a/src/components/common/MapView.vue b/src/components/common/MapView.vue index fbb94c7d..ec094548 100644 --- a/src/components/common/MapView.vue +++ b/src/components/common/MapView.vue @@ -13,7 +13,6 @@ import { ref, computed, useTemplateRef } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; -import { copyObjectTo } from '@/lib/common.ts'; import type { MapInstance, MapPosition } from '@/lib/map/base.ts'; import { createMapInstance } from '@/lib/map/index.ts'; @@ -38,7 +37,7 @@ const mapSupported = computed(() => !!mapInstance.value); const mapDependencyLoaded = computed(() => mapInstance.value?.dependencyLoaded || false); const finalMapStyle = computed>(() => { - const styles: Record = copyObjectTo(props.mapStyle, {}); + const styles: Record = Object.assign({}, props.mapStyle); if (props.height) { styles['height'] = props.height; diff --git a/src/components/mobile/TransactionTagSelectionSheet.vue b/src/components/mobile/TransactionTagSelectionSheet.vue index ed274574..6f8df092 100644 --- a/src/components/mobile/TransactionTagSelectionSheet.vue +++ b/src/components/mobile/TransactionTagSelectionSheet.vue @@ -93,7 +93,6 @@ import { useI18nUIComponents, showLoading, hideLoading } from '@/lib/ui/mobile.t import { TransactionTag } from '@/models/transaction_tag.ts'; import { useTransactionTagsStore } from '@/stores/transactionTag.ts'; -import { copyArrayTo } from '@/lib/common.ts'; import { type Framework7Dom, scrollToSelectedItem, scrollSheetToTop } from '@/lib/ui/mobile.ts'; const props = defineProps<{ @@ -117,7 +116,7 @@ const sheet = useTemplateRef('sheet'); const searchbar = useTemplateRef('searchbar'); const filterContent = ref(''); -const selectedItemIds = ref(copyArrayTo(props.modelValue, [])); +const selectedItemIds = ref(Array.from(props.modelValue)); const newTag = ref(null); const heightClass = ref(getHeightClass()); @@ -227,7 +226,7 @@ function onSearchBarFocus(): void { } function onSheetOpen(event: { $el: Framework7Dom }): void { - selectedItemIds.value = copyArrayTo(props.modelValue, []); + selectedItemIds.value = Array.from(props.modelValue); newTag.value = null; scrollToSelectedItem(event.$el, '.page-content', 'li.list-item-selected'); } diff --git a/src/lib/common.ts b/src/lib/common.ts index a2331bf0..156661e3 100644 --- a/src/lib/common.ts +++ b/src/lib/common.ts @@ -402,75 +402,6 @@ export function getNameByKeyValue(src: Record[] | Record | undefined, toObject: Record | undefined): Record { - if (!isObject(fromObject)) { - return toObject as Record; - } - - if (!isObject(toObject)) { - toObject = {}; - } - - for (const key in fromObject) { - if (!Object.prototype.hasOwnProperty.call(fromObject, key)) { - continue; - } - - const fromValue = fromObject[key]; - const toValue = toObject[key]; - - if (isArray(fromValue)) { - toObject[key] = copyArrayTo(fromValue, toValue as unknown[]); - } else if (isObject(fromValue)) { - toObject[key] = copyObjectTo(fromValue as Record, toValue as Record); - } else { - if (fromValue !== toValue) { - toObject[key] = fromValue; - } - } - } - - return toObject; -} - -export function copyArrayTo(fromArray: T[], toArray: T[]): T[] { - if (!isArray(fromArray)) { - return toArray; - } - - if (!isArray(toArray)) { - toArray = []; - } - - for (let i = 0; i < fromArray.length; i++) { - const fromValue = fromArray[i]; - - if (toArray.length > i) { - const toValue = toArray[i]; - - if (isArray(fromValue)) { - toArray[i] = copyArrayTo(fromValue as unknown[], toValue as unknown[]) as T; - } else if (isObject(fromValue)) { - toArray[i] = copyObjectTo(fromValue as Record, toValue as Record) as T; - } else { - if (fromValue !== toValue) { - toArray[i] = fromValue; - } - } - } else { - if (isArray(fromValue)) { - toArray.push(copyArrayTo(fromValue as unknown[], []) as T); - } else if (isObject(fromValue)) { - toArray.push(copyObjectTo(fromValue as Record, {}) as T); - } else { - toArray.push(fromValue); - } - } - } - - return toArray; -} - export function arrayContainsFieldValue(array: Record[], fieldName: string, value: T): boolean { if (!value || !array || !array.length) { return false; diff --git a/src/locales/helpers.ts b/src/locales/helpers.ts index 29fe8b0a..80cb1ec6 100644 --- a/src/locales/helpers.ts +++ b/src/locales/helpers.ts @@ -110,8 +110,7 @@ import { isObject, isString, isNumber, - isBoolean, - copyArrayTo + isBoolean } from '@/lib/common.ts'; import { @@ -990,11 +989,11 @@ export function useI18n() { let defaultCategories: PresetCategory[] = []; if (categoryType === CategoryType.Income) { - defaultCategories = copyArrayTo(DEFAULT_INCOME_CATEGORIES, []); + defaultCategories = DEFAULT_INCOME_CATEGORIES; } else if (categoryType === CategoryType.Expense) { - defaultCategories = copyArrayTo(DEFAULT_EXPENSE_CATEGORIES, []); + defaultCategories = DEFAULT_EXPENSE_CATEGORIES; } else if (categoryType === CategoryType.Transfer) { - defaultCategories = copyArrayTo(DEFAULT_TRANSFER_CATEGORIES, []); + defaultCategories = DEFAULT_TRANSFER_CATEGORIES; } for (let j = 0; j < defaultCategories.length; j++) { diff --git a/src/views/base/settings/AccountFilterSettingPageBase.ts b/src/views/base/settings/AccountFilterSettingPageBase.ts index 77154645..fd28fb9e 100644 --- a/src/views/base/settings/AccountFilterSettingPageBase.ts +++ b/src/views/base/settings/AccountFilterSettingPageBase.ts @@ -7,7 +7,6 @@ import { useStatisticsStore } from '@/stores/statistics.ts'; import type { Account, AccountCategoriesWithVisibleCount } from '@/models/account.ts'; -import { copyObjectTo } from '@/lib/common.ts'; import { getCategorizedAccountsWithVisibleCount, selectAccountOrSubAccounts, @@ -73,10 +72,10 @@ export function useAccountFilterSettingPageBase(type?: string) { } if (type === 'statisticsDefault') { - filterAccountIds.value = copyObjectTo(settingsStore.appSettings.statistics.defaultAccountFilter, allAccountIds) as Record; + filterAccountIds.value = Object.assign(allAccountIds, settingsStore.appSettings.statistics.defaultAccountFilter); return true; } else if (type === 'statisticsCurrent') { - filterAccountIds.value = copyObjectTo(statisticsStore.transactionStatisticsFilter.filterAccountIds, allAccountIds) as Record; + filterAccountIds.value = Object.assign(allAccountIds, statisticsStore.transactionStatisticsFilter.filterAccountIds); return true; } else if (type === 'transactionListCurrent') { for (const accountId in transactionsStore.allFilterAccountIds) { diff --git a/src/views/base/settings/CategoryFilterSettingPageBase.ts b/src/views/base/settings/CategoryFilterSettingPageBase.ts index 5303cf4f..72f94156 100644 --- a/src/views/base/settings/CategoryFilterSettingPageBase.ts +++ b/src/views/base/settings/CategoryFilterSettingPageBase.ts @@ -11,7 +11,6 @@ import { CategoryType } from '@/core/category.ts'; import type { TransactionCategory, TransactionCategoriesWithVisibleCount } from '@/models/transaction_category.ts'; import { - copyObjectTo, arrayItemToObjectField } from '@/lib/common.ts'; import { @@ -96,10 +95,10 @@ export function useCategoryFilterSettingPageBase(type?: string, allowCategoryTyp } if (type === 'statisticsDefault') { - filterCategoryIds.value = copyObjectTo(settingsStore.appSettings.statistics.defaultTransactionCategoryFilter, allCategoryIds) as Record; + filterCategoryIds.value = Object.assign(allCategoryIds, settingsStore.appSettings.statistics.defaultTransactionCategoryFilter); return true; } else if (type === 'statisticsCurrent') { - filterCategoryIds.value = copyObjectTo(statisticsStore.transactionStatisticsFilter.filterCategoryIds, allCategoryIds) as Record; + filterCategoryIds.value = Object.assign(allCategoryIds, statisticsStore.transactionStatisticsFilter.filterCategoryIds); return true; } else if (type === 'transactionListCurrent') { for (const categoryId in transactionsStore.allFilterCategoryIds) {