use for-of statements to replace for and for-in

This commit is contained in:
MaysWind
2025-09-09 23:48:42 +08:00
parent c75a902d84
commit 34c5a1750e
50 changed files with 368 additions and 460 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ export function useExchangeRatesPageBase() {
return getAllDisplayExchangeRates(exchangeRatesData.value);
});
function getConvertedAmount(baseAmount: number | '', fromExchangeRate: LatestExchangeRate | LocalizedLatestExchangeRate, toExchangeRate: LatestExchangeRate | LocalizedLatestExchangeRate): number | '' | null {
function getConvertedAmount(baseAmount: number | '', fromExchangeRate?: LatestExchangeRate | LocalizedLatestExchangeRate, toExchangeRate?: LatestExchangeRate | LocalizedLatestExchangeRate): number | '' | null {
if (!fromExchangeRate || !toExchangeRate) {
return '';
}
@@ -52,8 +52,8 @@ export function useAccountEditPageBaseBase() {
}
if (account.value.type === AccountType.MultiSubAccounts.type) {
for (let i = 0; i < subAccounts.value.length; i++) {
problemMessage = getInputEmptyProblemMessage(subAccounts.value[i], true);
for (const subAccount of subAccounts.value) {
problemMessage = getInputEmptyProblemMessage(subAccount, true);
if (problemMessage) {
return problemMessage;
@@ -132,9 +132,9 @@ export function useAccountEditPageBaseBase() {
subAccounts.value = [];
if (newAccount.subAccounts && newAccount.subAccounts.length > 0) {
for (let i = 0; i < newAccount.subAccounts.length; i++) {
for (const oldSubAccount of newAccount.subAccounts) {
const subAccount: Account = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
subAccount.fillFrom(newAccount.subAccounts[i]);
subAccount.fillFrom(oldSubAccount);
subAccounts.value.push(subAccount);
}
@@ -150,7 +150,7 @@ export function useReconciliationStatementPageBase() {
let currency = defaultCurrency.value;
if (allAccountsMap.value[transaction.sourceAccountId]) {
currency = allAccountsMap.value[transaction.sourceAccountId].currency;
currency = allAccountsMap.value[transaction.sourceAccountId]!.currency;
}
return formatAmountToLocalizedNumeralsWithCurrency(transaction.sourceAmount, currency);
@@ -160,7 +160,7 @@ export function useReconciliationStatementPageBase() {
let currency = defaultCurrency.value;
if (allAccountsMap.value[transaction.destinationAccountId]) {
currency = allAccountsMap.value[transaction.destinationAccountId].currency;
currency = allAccountsMap.value[transaction.destinationAccountId]!.currency;
}
return formatAmountToLocalizedNumeralsWithCurrency(transaction.destinationAmount, currency);
@@ -172,12 +172,12 @@ export function useReconciliationStatementPageBase() {
if (transaction.type === TransactionType.Transfer && transaction.destinationAccountId === accountId.value) {
if (allAccountsMap.value[transaction.destinationAccountId]) {
currency = allAccountsMap.value[transaction.destinationAccountId].currency;
isLiabilityAccount = allAccountsMap.value[transaction.destinationAccountId].isLiability;
currency = allAccountsMap.value[transaction.destinationAccountId]!.currency;
isLiabilityAccount = allAccountsMap.value[transaction.destinationAccountId]!.isLiability;
}
} else if (allAccountsMap.value[transaction.sourceAccountId]) {
currency = allAccountsMap.value[transaction.sourceAccountId].currency;
isLiabilityAccount = allAccountsMap.value[transaction.sourceAccountId].isLiability;
currency = allAccountsMap.value[transaction.sourceAccountId]!.currency;
isLiabilityAccount = allAccountsMap.value[transaction.sourceAccountId]!.isLiability;
}
if (isLiabilityAccount) {
@@ -8,6 +8,7 @@ import { useTransactionsStore } from '@/stores/transaction.ts';
import { useStatisticsStore } from '@/stores/statistics.ts';
import { useOverviewStore } from '@/stores/overview.ts';
import { keys, keysIfValueEquals, values } from '@/core/base.ts';
import { CategoryType } from '@/core/category.ts';
import type { TransactionCategory, TransactionCategoriesWithVisibleCount } from '@/models/transaction_category.ts';
@@ -80,13 +81,7 @@ export function useCategoryFilterSettingPageBase(type?: CategoryFilterType, allo
function loadFilterCategoryIds(): boolean {
const allCategoryIds: Record<string, boolean> = {};
for (const categoryId in transactionCategoriesStore.allTransactionCategoriesMap) {
if (!Object.prototype.hasOwnProperty.call(transactionCategoriesStore.allTransactionCategoriesMap, categoryId)) {
continue;
}
const category = transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
for (const category of values(transactionCategoriesStore.allTransactionCategoriesMap)) {
if (allowCategoryTypes && !allowCategoryTypes[category.type]) {
continue;
}
@@ -108,17 +103,13 @@ export function useCategoryFilterSettingPageBase(type?: CategoryFilterType, allo
filterCategoryIds.value = Object.assign(allCategoryIds, settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage);
return true;
} else if (type === 'transactionListCurrent') {
for (const categoryId in transactionsStore.allFilterCategoryIds) {
if (!Object.prototype.hasOwnProperty.call(transactionsStore.allFilterCategoryIds, categoryId)) {
continue;
}
for (const categoryId of keysIfValueEquals(transactionsStore.allFilterCategoryIds, true)) {
const category = transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
if (category && (!category.subCategories || !category.subCategories.length)) {
allCategoryIds[category.id] = false;
} else if (category) {
selectAllSubCategories(allCategoryIds, category, false);
selectAllSubCategories(allCategoryIds, false, category);
}
}
@@ -135,11 +126,7 @@ export function useCategoryFilterSettingPageBase(type?: CategoryFilterType, allo
let finalCategoryIds = '';
let changed = true;
for (const categoryId in filterCategoryIds.value) {
if (!Object.prototype.hasOwnProperty.call(filterCategoryIds.value, categoryId)) {
continue;
}
for (const categoryId of keys(filterCategoryIds.value)) {
const category = transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
if (!category) {
@@ -396,9 +396,9 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
});
watch(() => transaction.value.timeZone, (newValue) => {
for (let i = 0; i < allTimezones.value.length; i++) {
if (allTimezones.value[i].name === newValue) {
transaction.value.utcOffset = allTimezones.value[i].utcOffsetMinutes;
for (const timezone of allTimezones.value) {
if (timezone.name === newValue) {
transaction.value.utcOffset = timezone.utcOffsetMinutes;
break;
}
}