Skip to content

Commit 8dc30c3

Browse files
committed
Test with clearInternals
1 parent 305799c commit 8dc30c3

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/OnyxUtils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ const mergeQueue: Record<OnyxKey, Array<OnyxValue<OnyxKey>>> = {};
5252
const 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,12 @@ function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge): Array<
14311431
return promises;
14321432
}
14331433

1434+
function clearInternals(): void {
1435+
callbackToStateMapping = {};
1436+
onyxKeyToSubscriptionIDs = new Map();
1437+
lastConnectionCallbackData = new Map();
1438+
}
1439+
14341440
const OnyxUtils = {
14351441
METHOD,
14361442
getMergeQueue,
@@ -1480,6 +1486,7 @@ const OnyxUtils = {
14801486
addKeyToRecentlyAccessedIfNeeded,
14811487
reduceCollectionWithSelector,
14821488
updateSnapshots,
1489+
clearInternals,
14831490
};
14841491

14851492
GlobalSettings.addGlobalSettingsChangeListener(({enablePerformanceMetrics}) => {

tests/perf-test/Onyx.perf-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const mockedReportActionsMap = getRandomReportActions(collectionKey);
2525

2626
const clearOnyxAfterEachMeasure = async () => {
2727
await Onyx.clear();
28+
OnyxUtils.clearInternals();
2829
};
2930

3031
describe('Onyx', () => {
@@ -39,6 +40,7 @@ describe('Onyx', () => {
3940

4041
afterEach(async () => {
4142
await Onyx.clear();
43+
OnyxUtils.clearInternals();
4244
});
4345

4446
describe('set', () => {

tests/perf-test/OnyxConnectionManager.perf-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {Connection} from '../../lib/OnyxConnectionManager';
44
import connectionManager from '../../lib/OnyxConnectionManager';
55
import createDeferredTask from '../../lib/createDeferredTask';
66
import {getRandomReportActions} from '../utils/collections/reportActions';
7+
import OnyxUtils from '../../lib/OnyxUtils';
78

89
const ONYXKEYS = {
910
TEST_KEY: 'test',
@@ -38,6 +39,7 @@ const resetConectionManagerAfterEachMeasure = () => {
3839

3940
const clearOnyxAfterEachMeasure = async () => {
4041
await Onyx.clear();
42+
OnyxUtils.clearInternals();
4143
};
4244

4345
describe('OnyxConnectionManager', () => {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const mockedReportActionsKeys = Object.keys(mockedReportActionsMap);
4545

4646
const clearOnyxAfterEachMeasure = async () => {
4747
await Onyx.clear();
48+
OnyxUtils.clearInternals();
4849
};
4950

5051
describe('OnyxUtils', () => {
@@ -60,6 +61,7 @@ describe('OnyxUtils', () => {
6061

6162
afterEach(async () => {
6263
await Onyx.clear();
64+
OnyxUtils.clearInternals();
6365
});
6466

6567
describe('getMergeQueue', () => {

tests/perf-test/useOnyx.perf-test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {measureRenders} from 'reassure';
55
import type {FetchStatus, OnyxEntry, OnyxKey, OnyxValue, ResultMetadata, UseOnyxOptions} from '../../lib';
66
import Onyx, {useOnyx} from '../../lib';
77
import StorageMock from '../../lib/storage';
8+
import OnyxUtils from '../../lib/OnyxUtils';
89

910
const ONYXKEYS = {
1011
TEST_KEY: 'test',
@@ -49,6 +50,7 @@ function UseOnyxWrapper({onyxKey, onyxOptions}: UseOnyxWrapperProps) {
4950

5051
const clearOnyxAfterEachMeasure = async () => {
5152
await Onyx.clear();
53+
OnyxUtils.clearInternals();
5254
};
5355

5456
describe('useOnyx', () => {
@@ -61,6 +63,7 @@ describe('useOnyx', () => {
6163

6264
afterEach(async () => {
6365
await Onyx.clear();
66+
OnyxUtils.clearInternals();
6467
});
6568

6669
describe('misc', () => {

0 commit comments

Comments
 (0)