Skip to content

Commit fa12c19

Browse files
committed
Reintroduce clearOnyxUtilsInternals
1 parent ec27edb commit fa12c19

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

lib/OnyxUtils.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ const METHOD = {
4848
type OnyxMethod = ValueOf<typeof METHOD>;
4949

5050
// Key/value store of Onyx key and arrays of values to merge
51-
const mergeQueue: Record<OnyxKey, Array<OnyxValue<OnyxKey>>> = {};
52-
const mergeQueuePromise: Record<OnyxKey, Promise<void>> = {};
51+
let mergeQueue: Record<OnyxKey, Array<OnyxValue<OnyxKey>>> = {};
52+
let mergeQueuePromise: Record<OnyxKey, Promise<void>> = {};
5353

5454
// Holds a mapping of all the React components that want their state subscribed to a store key
55-
const callbackToStateMapping: Record<string, Mapping<OnyxKey>> = {};
55+
let callbackToStateMapping: Record<string, Mapping<OnyxKey>> = {};
5656

5757
// Keeps a copy of the values of the onyx collection keys as a map for faster lookups
5858
let onyxCollectionKeySet = new Set<OnyxKey>();
5959

6060
// Holds a mapping of the connected key to the subscriptionID for faster lookups
61-
const onyxKeyToSubscriptionIDs = new Map();
61+
let onyxKeyToSubscriptionIDs = new Map();
6262

6363
// Optional user-provided key value states set when Onyx initializes or clears
6464
let defaultKeyStates: Record<OnyxKey, OnyxValue<OnyxKey>> = {};
@@ -67,7 +67,7 @@ let batchUpdatesPromise: Promise<void> | null = null;
6767
let batchUpdatesQueue: Array<() => void> = [];
6868

6969
// Used for comparison with a new update to avoid invoking the Onyx.connect callback with the same data.
70-
const lastConnectionCallbackData = new Map<number, OnyxValue<OnyxKey>>();
70+
let lastConnectionCallbackData = new Map<number, OnyxValue<OnyxKey>>();
7171

7272
let snapshotKey: OnyxKey | null = null;
7373

@@ -1431,6 +1431,15 @@ function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge): Array<
14311431
return promises;
14321432
}
14331433

1434+
function clearOnyxUtilsInternals() {
1435+
mergeQueue = {};
1436+
mergeQueuePromise = {};
1437+
callbackToStateMapping = {};
1438+
onyxKeyToSubscriptionIDs = new Map();
1439+
batchUpdatesQueue = [];
1440+
lastConnectionCallbackData = new Map();
1441+
}
1442+
14341443
const OnyxUtils = {
14351444
METHOD,
14361445
getMergeQueue,
@@ -1480,6 +1489,12 @@ const OnyxUtils = {
14801489
addKeyToRecentlyAccessedIfNeeded,
14811490
reduceCollectionWithSelector,
14821491
updateSnapshots,
1492+
mergeQueue,
1493+
mergeQueuePromise,
1494+
callbackToStateMapping,
1495+
defaultKeyStates,
1496+
batchUpdatesPromise,
1497+
batchUpdatesQueue,
14831498
};
14841499

14851500
GlobalSettings.addGlobalSettingsChangeListener(({enablePerformanceMetrics}) => {
@@ -1532,3 +1547,4 @@ GlobalSettings.addGlobalSettingsChangeListener(({enablePerformanceMetrics}) => {
15321547

15331548
export type {OnyxMethod};
15341549
export default OnyxUtils;
1550+
export {clearOnyxUtilsInternals};

tests/perf-test/OnyxUtils.perf-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {OnyxKey, Selector} from '../../lib';
44
import Onyx from '../../lib';
55
import StorageMock from '../../lib/storage';
66
import OnyxCache from '../../lib/OnyxCache';
7-
import OnyxUtils from '../../lib/OnyxUtils';
7+
import OnyxUtils, {clearOnyxUtilsInternals} from '../../lib/OnyxUtils';
88
import type GenericCollection from '../utils/GenericCollection';
99
import type {Mapping, OnyxUpdate} from '../../lib/Onyx';
1010
import createDeferredTask from '../../lib/createDeferredTask';
@@ -44,6 +44,7 @@ const mockedReportActionsMap = getRandomReportActions(collectionKey);
4444
const mockedReportActionsKeys = Object.keys(mockedReportActionsMap);
4545

4646
const clearOnyxAfterEachMeasure = async () => {
47+
clearOnyxUtilsInternals();
4748
await Onyx.clear();
4849
};
4950

@@ -59,6 +60,7 @@ describe('OnyxUtils', () => {
5960
});
6061

6162
afterEach(async () => {
63+
clearOnyxUtilsInternals();
6264
await Onyx.clear();
6365
});
6466

0 commit comments

Comments
 (0)