Skip to content

Commit af1e817

Browse files
committed
Rename connectionID to connection across the App
1 parent b7c66a6 commit af1e817

30 files changed

+450
-449
lines changed

Diff for: src/hooks/useLastAccessedReportID.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {useCallback, useSyncExternalStore} from 'react';
2-
import type {OnyxCollection} from 'react-native-onyx';
2+
import type {ConnectionMetadata, OnyxCollection} from 'react-native-onyx';
33
import Onyx from 'react-native-onyx';
44
import {getPolicyEmployeeListByIdWithoutCurrentUser} from '@libs/PolicyUtils';
55
import * as ReportUtils from '@libs/ReportUtils';
@@ -23,11 +23,11 @@ let policies: OnyxCollection<Policy> = {};
2323
let accountID: number | undefined;
2424
let isFirstTimeNewExpensifyUser = false;
2525

26-
let reportsConnection: number;
27-
let reportMetadataConnection: number;
28-
let policiesConnection: number;
29-
let accountIDConnection: number;
30-
let isFirstTimeNewExpensifyUserConnection: number;
26+
let reportsConnection: ConnectionMetadata | null;
27+
let reportMetadataConnection: ConnectionMetadata | null;
28+
let policiesConnection: ConnectionMetadata | null;
29+
let accountIDConnection: ConnectionMetadata | null;
30+
let isFirstTimeNewExpensifyUserConnection: ConnectionMetadata | null;
3131

3232
function notifySubscribers() {
3333
subscribers.forEach((subscriber) => subscriber());
@@ -82,23 +82,23 @@ function subscribeToOnyxData() {
8282
function unsubscribeFromOnyxData() {
8383
if (reportsConnection) {
8484
Onyx.disconnect(reportsConnection);
85-
reportsConnection = 0;
85+
reportsConnection = null;
8686
}
8787
if (reportMetadataConnection) {
8888
Onyx.disconnect(reportMetadataConnection);
89-
reportMetadataConnection = 0;
89+
reportMetadataConnection = null;
9090
}
9191
if (policiesConnection) {
9292
Onyx.disconnect(policiesConnection);
93-
policiesConnection = 0;
93+
policiesConnection = null;
9494
}
9595
if (accountIDConnection) {
9696
Onyx.disconnect(accountIDConnection);
97-
accountIDConnection = 0;
97+
accountIDConnection = null;
9898
}
9999
if (isFirstTimeNewExpensifyUserConnection) {
100100
Onyx.disconnect(isFirstTimeNewExpensifyUserConnection);
101-
isFirstTimeNewExpensifyUserConnection = 0;
101+
isFirstTimeNewExpensifyUserConnection = null;
102102
}
103103
}
104104

Diff for: src/libs/E2E/actions/e2eLogin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function (): Promise<boolean> {
4343

4444
// Subscribe to auth token, to check if we are authenticated
4545
return new Promise((resolve, reject) => {
46-
const connectionId = Onyx.connect({
46+
const connection = Onyx.connect({
4747
key: ONYXKEYS.SESSION,
4848
callback: (session) => {
4949
if (session?.authToken == null || session.authToken.length === 0) {
@@ -67,7 +67,7 @@ export default function (): Promise<boolean> {
6767
}
6868
// signal that auth was completed
6969
resolve(neededLogin);
70-
Onyx.disconnect(connectionId);
70+
Onyx.disconnect(connection);
7171
},
7272
});
7373
});

Diff for: src/libs/E2E/actions/waitForAppLoaded.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import ONYXKEYS from '@src/ONYXKEYS';
44
// Once we get the sidebar loaded end mark we know that the app is ready to be used:
55
export default function waitForAppLoaded(): Promise<void> {
66
return new Promise((resolve) => {
7-
const connectionId = Onyx.connect({
7+
const connection = Onyx.connect({
88
key: ONYXKEYS.IS_SIDEBAR_LOADED,
99
callback: (isSidebarLoaded) => {
1010
if (!isSidebarLoaded) {
1111
return;
1212
}
1313

1414
resolve();
15-
Onyx.disconnect(connectionId);
15+
Onyx.disconnect(connection);
1616
},
1717
});
1818
});

Diff for: src/libs/actions/App.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ AppState.addEventListener('change', (nextAppState) => {
184184
function getPolicyParamsForOpenOrReconnect(): Promise<PolicyParamsForOpenOrReconnect> {
185185
return new Promise((resolve) => {
186186
isReadyToOpenApp.then(() => {
187-
const connectionID = Onyx.connect({
187+
const connection = Onyx.connect({
188188
key: ONYXKEYS.COLLECTION.POLICY,
189189
waitForCollectionCallback: true,
190190
callback: (policies) => {
191-
Onyx.disconnect(connectionID);
191+
Onyx.disconnect(connection);
192192
resolve({policyIDList: getNonOptimisticPolicyIDs(policies)});
193193
},
194194
});

Diff for: src/libs/actions/Device/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function getDeviceID(): Promise<string | null> {
1616
return;
1717
}
1818

19-
const connectionID = Onyx.connect({
19+
const connection = Onyx.connect({
2020
key: ONYXKEYS.DEVICE_ID,
2121
callback: (id) => {
22-
Onyx.disconnect(connectionID);
22+
Onyx.disconnect(connection);
2323
deviceID = id ?? null;
2424
return resolve(id ?? null);
2525
},

Diff for: src/libs/actions/Download.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ function setDownload(sourceID: string, isDownloading: boolean): Promise<void | v
99
}
1010

1111
function clearDownloads() {
12-
const connectionID = Onyx.connect({
12+
const connection = Onyx.connect({
1313
key: ONYXKEYS.COLLECTION.DOWNLOAD,
1414
waitForCollectionCallback: true,
1515
callback: (records) => {
16-
Onyx.disconnect(connectionID);
16+
Onyx.disconnect(connection);
1717
const downloadsToDelete: Record<string, null> = {};
1818
Object.keys(records ?? {}).forEach((recordKey) => {
1919
downloadsToDelete[recordKey] = null;

Diff for: src/libs/actions/MapboxToken.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {isAfter} from 'date-fns';
22
import type {NativeEventSubscription} from 'react-native';
33
import {AppState} from 'react-native';
4+
import type {ConnectionMetadata} from 'react-native-onyx';
45
import Onyx from 'react-native-onyx';
56
import * as ActiveClientManager from '@libs/ActiveClientManager';
67
import * as API from '@libs/API';
@@ -17,8 +18,8 @@ Onyx.connect({
1718
},
1819
});
1920

20-
let connectionIDForToken: number | null;
21-
let connectionIDForNetwork: number | null;
21+
let tokenConnection: ConnectionMetadata | null;
22+
let networkConnection: ConnectionMetadata | null;
2223
let appStateSubscription: NativeEventSubscription | null;
2324
let currentToken: MapboxAccessToken | undefined;
2425
let refreshTimeoutID: NodeJS.Timeout | undefined;
@@ -57,13 +58,13 @@ const fetchToken = () => {
5758
};
5859

5960
const init = () => {
60-
if (connectionIDForToken) {
61+
if (tokenConnection) {
6162
console.debug('[MapboxToken] init() is already listening to Onyx so returning early');
6263
return;
6364
}
6465

6566
// When the token changes in Onyx, the expiration needs to be checked so a new token can be retrieved.
66-
connectionIDForToken = Onyx.connect({
67+
tokenConnection = Onyx.connect({
6768
key: ONYXKEYS.MAPBOX_ACCESS_TOKEN,
6869
callback: (token) => {
6970
// Only the leader should be in charge of the mapbox token, or else when you have multiple tabs open, the Onyx connection fires multiple times
@@ -116,9 +117,9 @@ const init = () => {
116117
});
117118
}
118119

119-
if (!connectionIDForNetwork) {
120+
if (!networkConnection) {
120121
let network: Network | undefined;
121-
connectionIDForNetwork = Onyx.connect({
122+
networkConnection = Onyx.connect({
122123
key: ONYXKEYS.NETWORK,
123124
callback: (value) => {
124125
// When the network reconnects, check if the token has expired. If it has, then clearing the token will
@@ -139,13 +140,13 @@ const init = () => {
139140

140141
const stop = () => {
141142
console.debug('[MapboxToken] Stopping all listeners and timers');
142-
if (connectionIDForToken) {
143-
Onyx.disconnect(connectionIDForToken);
144-
connectionIDForToken = null;
143+
if (tokenConnection) {
144+
Onyx.disconnect(tokenConnection);
145+
tokenConnection = null;
145146
}
146-
if (connectionIDForNetwork) {
147-
Onyx.disconnect(connectionIDForNetwork);
148-
connectionIDForNetwork = null;
147+
if (networkConnection) {
148+
Onyx.disconnect(networkConnection);
149+
networkConnection = null;
149150
}
150151
if (appStateSubscription) {
151152
appStateSubscription.remove();

Diff for: src/libs/actions/TransactionEdit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ function removeBackupTransaction(transactionID: string) {
2727
}
2828

2929
function restoreOriginalTransactionFromBackup(transactionID: string, isDraft: boolean) {
30-
const connectionID = Onyx.connect({
30+
const connection = Onyx.connect({
3131
key: `${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`,
3232
callback: (backupTransaction) => {
33-
Onyx.disconnect(connectionID);
33+
Onyx.disconnect(connection);
3434

3535
// Use set to completely overwrite the original transaction
3636
Onyx.set(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, backupTransaction ?? null);

Diff for: src/libs/actions/User.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ function triggerNotifications(onyxUpdates: OnyxServerUpdate[]) {
482482

483483
const isChannelMuted = (reportId: string) =>
484484
new Promise((resolve) => {
485-
const connectionId = Onyx.connect({
485+
const connection = Onyx.connect({
486486
key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`,
487487
callback: (report) => {
488-
Onyx.disconnect(connectionId);
488+
Onyx.disconnect(connection);
489489

490490
resolve(
491491
!report?.notificationPreference ||

Diff for: src/libs/markAllPolicyReportsAsRead.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ReportActionFile from './actions/Report';
55
import * as ReportUtils from './ReportUtils';
66

77
export default function markAllPolicyReportsAsRead(policyID: string) {
8-
const connectionID = Onyx.connect({
8+
const connection = Onyx.connect({
99
key: ONYXKEYS.COLLECTION.REPORT,
1010
waitForCollectionCallback: true,
1111
callback: (allReports) => {
@@ -26,7 +26,7 @@ export default function markAllPolicyReportsAsRead(policyID: string) {
2626

2727
delay += 1000;
2828
});
29-
Onyx.disconnect(connectionID);
29+
Onyx.disconnect(connection);
3030
},
3131
});
3232
}

Diff for: src/libs/migrations/CheckForPreviousReportActionID.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction'
77

88
function getReportActionsFromOnyx(): Promise<OnyxCollection<OnyxTypes.ReportActions>> {
99
return new Promise((resolve) => {
10-
const connectionID = Onyx.connect({
10+
const connection = Onyx.connect({
1111
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
1212
waitForCollectionCallback: true,
1313
callback: (allReportActions) => {
14-
Onyx.disconnect(connectionID);
14+
Onyx.disconnect(connection);
1515
return resolve(allReportActions);
1616
},
1717
});

Diff for: src/libs/migrations/KeyReportActionsDraftByReportActionID.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type ReportActionsDraftsKey = `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFT
1515
*/
1616
export default function () {
1717
return new Promise<void | void[]>((resolve) => {
18-
const connectionID = Onyx.connect({
18+
const connection = Onyx.connect({
1919
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS,
2020
waitForCollectionCallback: true,
2121
// eslint-disable-next-line @typescript-eslint/no-misused-promises
2222
callback: (allReportActionsDrafts) => {
23-
Onyx.disconnect(connectionID);
23+
Onyx.disconnect(connection);
2424

2525
if (!allReportActionsDrafts) {
2626
Log.info('[Migrate Onyx] Skipped migration KeyReportActionsDraftByReportActionID because there were no reportActionsDrafts');

Diff for: src/libs/migrations/NVPMigration.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export default function () {
2828
const resolveWhenDone = after(Object.entries(migrations).length + 2, () => resolve());
2929

3030
for (const [oldKey, newKey] of Object.entries(migrations)) {
31-
const connectionID = Onyx.connect({
31+
const connection = Onyx.connect({
3232
key: oldKey as OnyxKey,
3333
callback: (value) => {
34-
Onyx.disconnect(connectionID);
34+
Onyx.disconnect(connection);
3535
if (value === undefined) {
3636
resolveWhenDone();
3737
return;
@@ -43,10 +43,10 @@ export default function () {
4343
},
4444
});
4545
}
46-
const connectionIDAccount = Onyx.connect({
46+
const accountConnection = Onyx.connect({
4747
key: ONYXKEYS.ACCOUNT,
4848
callback: (value: OnyxEntry<Account & {activePolicyID?: string}>) => {
49-
Onyx.disconnect(connectionIDAccount);
49+
Onyx.disconnect(accountConnection);
5050
if (!value?.activePolicyID) {
5151
resolveWhenDone();
5252
return;
@@ -60,11 +60,11 @@ export default function () {
6060
}).then(resolveWhenDone);
6161
},
6262
});
63-
const connectionIDRecentlyUsedTags = Onyx.connect({
63+
const recentlyUsedTagsConnection = Onyx.connect({
6464
key: ONYXKEYS.COLLECTION.OLD_POLICY_RECENTLY_USED_TAGS,
6565
waitForCollectionCallback: true,
6666
callback: (value) => {
67-
Onyx.disconnect(connectionIDRecentlyUsedTags);
67+
Onyx.disconnect(recentlyUsedTagsConnection);
6868
if (!value) {
6969
resolveWhenDone();
7070
return;

Diff for: src/libs/migrations/Participants.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ type OldReportCollection = Record<ReportKey, NullishDeep<OldReport>>;
1111

1212
function getReports(): Promise<OnyxCollection<OldReport>> {
1313
return new Promise((resolve) => {
14-
const connectionID = Onyx.connect({
14+
const connection = Onyx.connect({
1515
key: ONYXKEYS.COLLECTION.REPORT,
1616
waitForCollectionCallback: true,
1717
callback: (reports) => {
18-
Onyx.disconnect(connectionID);
18+
Onyx.disconnect(connection);
1919
return resolve(reports);
2020
},
2121
});
@@ -24,10 +24,10 @@ function getReports(): Promise<OnyxCollection<OldReport>> {
2424

2525
function getCurrentUserAccountID(): Promise<number | undefined> {
2626
return new Promise((resolve) => {
27-
const connectionID = Onyx.connect({
27+
const connection = Onyx.connect({
2828
key: ONYXKEYS.SESSION,
2929
callback: (session) => {
30-
Onyx.disconnect(connectionID);
30+
Onyx.disconnect(connection);
3131
return resolve(session?.accountID);
3232
},
3333
});

Diff for: src/libs/migrations/PronounsMigration.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type {PersonalDetails as TPersonalDetails} from '@src/types/onyx';
77

88
function getCurrentUserAccountIDFromOnyx(): Promise<number> {
99
return new Promise((resolve) => {
10-
const connectionID = Onyx.connect({
10+
const connection = Onyx.connect({
1111
key: ONYXKEYS.SESSION,
1212
callback: (val) => {
13-
Onyx.disconnect(connectionID);
13+
Onyx.disconnect(connection);
1414
return resolve(val?.accountID ?? -1);
1515
},
1616
});
@@ -19,10 +19,10 @@ function getCurrentUserAccountIDFromOnyx(): Promise<number> {
1919

2020
function getCurrentUserPersonalDetailsFromOnyx(currentUserAccountID: number): Promise<NonNullable<OnyxEntry<TPersonalDetails>> | null> {
2121
return new Promise((resolve) => {
22-
const connectionID = Onyx.connect({
22+
const connection = Onyx.connect({
2323
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
2424
callback: (val) => {
25-
Onyx.disconnect(connectionID);
25+
Onyx.disconnect(connection);
2626
return resolve(val?.[currentUserAccountID] ?? null);
2727
},
2828
});

Diff for: src/libs/migrations/RemoveEmptyReportActionsDrafts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ type ReportActionsDraftsKey = `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFT
1313
*/
1414
export default function (): Promise<void> {
1515
return new Promise<void>((resolve) => {
16-
const connectionID = Onyx.connect({
16+
const connection = Onyx.connect({
1717
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS,
1818
waitForCollectionCallback: true,
1919
callback: (allReportActionsDrafts) => {
20-
Onyx.disconnect(connectionID);
20+
Onyx.disconnect(connection);
2121

2222
if (!allReportActionsDrafts) {
2323
Log.info('[Migrate Onyx] Skipped migration RemoveEmptyReportActionsDrafts because there were no reportActionsDrafts');

Diff for: src/libs/migrations/RenameCardIsVirtual.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ type OldCard = Card & {isVirtual?: boolean};
1010
// This migration changes the property name on each card from card list from isVirtual to nameValuePairs.isVirtual
1111
export default function () {
1212
return new Promise<void>((resolve) => {
13-
const connectionID = Onyx.connect({
13+
const connection = Onyx.connect({
1414
key: ONYXKEYS.CARD_LIST,
1515
callback: (cardList: OnyxEntry<Record<string, OldCard>>) => {
16-
Onyx.disconnect(connectionID);
16+
Onyx.disconnect(connection);
1717

1818
if (!cardList || isEmptyObject(cardList)) {
1919
Log.info('[Migrate Onyx] Skipped migration RenameCardIsVirtual because there are no cards linked to the account');

0 commit comments

Comments
 (0)