Skip to content

Open source personal finance application

fix: remove broken cancelPersist — blockPersist already prevents writes

Ilya Komichevd01d80ec7b09
diff --git a/app/components/app/useInitApp.ts b/app/components/app/useInitApp.ts
index 59ab1708..a800e113 100644
--- a/app/components/app/useInitApp.ts
+++ b/app/components/app/useInitApp.ts
@@ -71,10 +71,6 @@ export function useInitApp() {
// and debounced persists from re-writing data after cleanup.
blockPersist()
- categoriesStore.cancelPersist()
- trnsStore.cancelPersist()
- walletsStore.cancelPersist()
-
categoriesStore.setCategories(null)
trnsStore.setTrns(null)
walletsStore.setWallets(null)
diff --git a/app/components/categories/useCategoriesStore.test.ts b/app/components/categories/useCategoriesStore.test.ts
index 852ea9f1..fde8d499 100644
--- a/app/components/categories/useCategoriesStore.test.ts
+++ b/app/components/categories/useCategoriesStore.test.ts
@@ -97,19 +97,6 @@ describe('useCategoriesStore', () => {
expect(store.items.c1!.name).toBe('Food')
})
- it('saves to localforage', async () => {
- const store = useCategoriesStore()
-
- store.saveCategory({
- id: 'c1',
- isUpdateChildCategoriesColor: false,
- values: makeCategory(),
- })
-
- const saved = await localforage.getItem<any>('finapp.categories')
- expect(saved).toHaveProperty('c1')
- })
-
it('pushes to offline queue immediately', () => {
const store = useCategoriesStore()
diff --git a/app/components/categories/useCategoriesStore.ts b/app/components/categories/useCategoriesStore.ts
index a0976998..1bb7e39c 100644
--- a/app/components/categories/useCategoriesStore.ts
+++ b/app/components/categories/useCategoriesStore.ts
@@ -31,7 +31,6 @@ const transfer: CategoryItem = {
}
type CategoriesStore = {
- cancelPersist: () => void
categoriesForBeParent: ComputedRef<CategoryId[]>
categoriesIdsForTrnValues: ComputedRef<CategoryId[]>
categoriesRootIds: ComputedRef<CategoryId[]>
@@ -316,7 +315,6 @@ export const useCategoriesStore = defineStore('categories', (): CategoriesStore
}
return {
- cancelPersist: () => debouncedPersist.cancel(),
categoriesForBeParent,
categoriesIdsForTrnValues,
categoriesRootIds,
diff --git a/app/components/trns/useTrnsStore.test.ts b/app/components/trns/useTrnsStore.test.ts
index e6c25f29..791a3696 100644
--- a/app/components/trns/useTrnsStore.test.ts
+++ b/app/components/trns/useTrnsStore.test.ts
@@ -118,16 +118,6 @@ describe('useTrnsStore', () => {
expect(trn1.amount).toBe(100)
})
- it('saves to localforage', async () => {
- const store = useTrnsStore()
- store.items = {}
-
- store.saveTrn({ id: 'trn1', values: makeTrn() })
-
- const saved = await localforage.getItem<any>('finapp.trns')
- expect(saved).toHaveProperty('trn1')
- })
-
it('pushes to offline queue immediately', () => {
const store = useTrnsStore()
store.items = {}
diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.ts
index 5d88017d..142949af 100644
--- a/app/components/trns/useTrnsStore.ts
+++ b/app/components/trns/useTrnsStore.ts
@@ -392,7 +392,6 @@ export const useTrnsStore = defineStore('trns', () => {
}
return {
- cancelPersist: () => debouncedPersist.cancel(),
computeTrnItem,
deleteTrn,
getRange,
diff --git a/app/components/user/useUserStore.ts b/app/components/user/useUserStore.ts
index 36156e89..e4fd29dc 100644
--- a/app/components/user/useUserStore.ts
+++ b/app/components/user/useUserStore.ts
@@ -189,10 +189,6 @@ export const useUserStore = defineStore('user', () => {
blockPersist()
try {
- categoriesStore.cancelPersist()
- trnsStore.cancelPersist()
- walletsStore.cancelPersist()
-
trnsStore.setTrns(null)
categoriesStore.setCategories(null)
walletsStore.setWallets(null)
@@ -221,9 +217,7 @@ export const useUserStore = defineStore('user', () => {
}
async function removeAllUserData() {
- categoriesStore.cancelPersist()
- trnsStore.cancelPersist()
- walletsStore.cancelPersist()
+ blockPersist()
trnsStore.setTrns(null)
categoriesStore.setCategories(null)
diff --git a/app/components/wallets/useWalletsStore.test.ts b/app/components/wallets/useWalletsStore.test.ts
index c70ac2cf..d3bf48ff 100644
--- a/app/components/wallets/useWalletsStore.test.ts
+++ b/app/components/wallets/useWalletsStore.test.ts
@@ -112,16 +112,6 @@ describe('useWalletsStore', () => {
expect(store.items!.w1!.name).toBe('Cash')
})
- it('saves to localforage', async () => {
- const store = useWalletsStore()
- store.items = {}
-
- store.saveWallet({ id: 'w1', values: makeWallet() })
-
- const saved = await localforage.getItem<any>('finapp.wallets')
- expect(saved).toHaveProperty('w1')
- })
-
it('pushes to offline queue immediately', () => {
const store = useWalletsStore()
store.items = {}
diff --git a/app/components/wallets/useWalletsStore.ts b/app/components/wallets/useWalletsStore.ts
index 4a60c9ee..806dd6a7 100644
--- a/app/components/wallets/useWalletsStore.ts
+++ b/app/components/wallets/useWalletsStore.ts
@@ -213,7 +213,6 @@ export const useWalletsStore = defineStore('wallets', () => {
}
return {
- cancelPersist: () => debouncedPersist.cancel(),
currenciesUsed,
deleteWallet,
hasItems,
diff --git a/app/composables/useStoreSync.ts b/app/composables/useStoreSync.ts
index 14c09152..37781156 100644
--- a/app/composables/useStoreSync.ts
+++ b/app/composables/useStoreSync.ts
@@ -32,17 +32,12 @@ export function isPersistBlocked(): boolean {
return _persistBlocked
}
-export type DebouncedPersist<T> = {
- (values: T): void
- cancel: () => void
-}
-
-export function createDebouncedPersist<T>(storageKey: string): DebouncedPersist<T> {
+export function createDebouncedPersist<T>(storageKey: string) {
return debounce((values: T) => {
if (_persistBlocked)
return
localforage.setItem(storageKey, values)
- }, 300, { edges: ['leading', 'trailing'] })
+ }, 300)
}
export function pushSaveOp<T extends Record<string, unknown>>(opts: {