Skip to content

Commit cd18848

Browse files
CedrikNikitaperonczyk
authored andcommitted
refactor: remove ui composableHelpers circular dependency
1 parent 713138a commit cd18848

File tree

7 files changed

+21
-22
lines changed

7 files changed

+21
-22
lines changed

src/composables/accounts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from '@/constants';
2020
import {
2121
createCallbackRegistry,
22+
createCustomScopedComposable,
2223
excludeFalsy,
2324
prepareAccountSelectOptions,
2425
watchUntilTruthy,
@@ -28,7 +29,6 @@ import migrateAccountsVuexToComposable from '@/migrations/001-accounts-vuex-to-c
2829
import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory';
2930

3031
import { useStorageRef } from './storageRef';
31-
import { createCustomScopedComposable } from './composablesHelpers';
3232
import { useAuth } from './auth';
3333

3434
const {

src/composables/addressBook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { STORAGE_KEYS, MODAL_ADDRESS_BOOK_IMPORT } from '@/constants';
1111
import { AddressBookEntryExists, AddressBookInvalidAddress, AddressBookRequiredFields } from '@/lib/errors';
1212
import {
1313
convertBlobToBase64,
14+
createCustomScopedComposable,
1415
getProtocolByAddress,
1516
handleUnknownError,
1617
selectFiles,
1718
pipe,
1819
} from '@/utils';
1920
import { tg as t } from '@/popup/plugins/i18n';
2021

21-
import { createCustomScopedComposable } from './composablesHelpers';
2222
import { useStorageRef } from './storageRef';
2323
import { useModals } from './modals';
2424

src/composables/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from '@/constants';
2020
import { STUB_ACCOUNT } from '@/constants/stubs';
2121
import {
22+
createCustomScopedComposable,
2223
decodeBase64,
2324
decrypt,
2425
encodeBase64,
@@ -36,7 +37,6 @@ import migrateMnemonicCordovaToIonic from '@/migrations/008-mnemonic-cordova-to-
3637

3738
import { useUi } from './ui';
3839
import { useModals } from './modals';
39-
import { createCustomScopedComposable } from './composablesHelpers';
4040
import { useStorageRef } from './storageRef';
4141

4242
const CHECK_FOR_SESSION_KEY_INTERVAL = 5000;

src/composables/composablesHelpers.ts

-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
import {
2-
effectScope,
32
getCurrentInstance,
43
onBeforeUnmount,
54
onMounted,
65
} from 'vue';
76
import { useConnection } from './connection';
87
import { useUi } from './ui';
98

10-
/**
11-
* Creates a custom effect scope for a composable to avoid disposing watchers
12-
* and computed properties when a Vue component is unmounted. The effect scope
13-
* is only created the first time you run the composable and is reused from that point on.
14-
*/
15-
export function createCustomScopedComposable<T>(composableBody: () => T) {
16-
let activeScope: T;
17-
return () => {
18-
if (!activeScope) {
19-
activeScope = effectScope(true).run(composableBody) || composableBody();
20-
}
21-
return activeScope;
22-
};
23-
}
24-
259
/**
2610
* Creates a function, that will monitor how many components is actually using the composable
2711
* and if the value is greater than 0 it will perform a polling based on the setInterval function.

src/composables/ui.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { RouteLocationRaw } from 'vue-router';
1010
import type { IOtherSettings } from '@/types';
1111
import { AUTHENTICATION_TIMEOUT_DEFAULT, STORAGE_KEYS } from '@/constants';
1212
import { ROUTE_ACCOUNT } from '@/popup/router/routeNames';
13+
import { createCustomScopedComposable } from '@/utils';
1314

1415
import migrateHiddenCardsVuexToComposable from '@/migrations/004-hidden-cards-vuex-to-composables';
1516
import migrateOtherSettingsVuexToComposable from '@/migrations/005-other-settings-vuex-to-composables';
1617
import migrateSecureLoginEnabledToBiometric from '@/migrations/009-secure-login-enabled-to-biometric';
1718

1819
import { useStorageRef } from './storageRef';
19-
import { createCustomScopedComposable } from './composablesHelpers';
2020

2121
export const useUi = createCustomScopedComposable(() => {
2222
/** Control the route that would be visible after opening the extension. */

src/protocols/aeternity/composables/aeNetworkSettings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed } from 'vue';
22
import type { NetworkTypeDefault } from '@/types';
33
import { NETWORK_TYPE_CUSTOM, NETWORK_TYPE_TESTNET } from '@/constants';
4-
import { createCustomScopedComposable } from '@/composables/composablesHelpers';
4+
import { createCustomScopedComposable } from '@/utils';
55
import { useNetworks } from '@/composables/networks';
66

77
import type { IAeNetworkPredefinedSettings, IAeNetworkSettings } from '@/protocols/aeternity/types';

src/utils/common.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/* eslint-disable no-use-before-define */
66

7-
import { WatchSource, watch } from 'vue';
7+
import { effectScope, WatchSource, watch } from 'vue';
88
import { defer, uniqWith } from 'lodash-es';
99
import BigNumber from 'bignumber.js';
1010
import { Share } from '@capacitor/share';
@@ -602,3 +602,18 @@ export function checkPasswordStrength(password: string): ObjectValues<typeof PAS
602602
}
603603
return PASSWORD_STRENGTH.strong;
604604
}
605+
606+
/**
607+
* Creates a custom effect scope for a composable to avoid disposing watchers
608+
* and computed properties when a Vue component is unmounted. The effect scope
609+
* is only created the first time you run the composable and is reused from that point on.
610+
*/
611+
export function createCustomScopedComposable<T>(composableBody: () => T) {
612+
let activeScope: T;
613+
return () => {
614+
if (!activeScope) {
615+
activeScope = effectScope(true).run(composableBody) || composableBody();
616+
}
617+
return activeScope;
618+
};
619+
}

0 commit comments

Comments
 (0)