Skip to content

Commit cd5e14c

Browse files
committed
Experiment 5
1 parent acb09d3 commit cd5e14c

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

jestSetup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ jest.mock('react-native-nitro-sqlite', () => ({
99
}));
1010

1111
jest.useRealTimers();
12+
13+
const unstable_batchedUpdates_jest = require('react-test-renderer').unstable_batchedUpdates;
14+
require('./lib/batch.native').default = unstable_batchedUpdates_jest;

lib/OnyxUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Logger from './Logger';
77
import type Onyx from './Onyx';
88
import cache, {TASK} from './OnyxCache';
99
import * as Str from './Str';
10+
import unstable_batchedUpdates from './batch';
1011
import Storage from './storage';
1112
import type {
1213
CollectionKey,
@@ -228,8 +229,14 @@ function maybeFlushBatchUpdates(): Promise<void> {
228229
* then the batch will be flushed on next frame.
229230
*/
230231
setTimeout(() => {
232+
const updatesCopy = batchUpdatesQueue;
231233
batchUpdatesQueue = [];
232234
batchUpdatesPromise = null;
235+
unstable_batchedUpdates(() => {
236+
for (const applyUpdates of updatesCopy) {
237+
applyUpdates();
238+
}
239+
});
233240

234241
resolve();
235242
}, 0);

lib/batch.native.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {unstable_batchedUpdates} from 'react-native';
2+
3+
export default unstable_batchedUpdates;

lib/batch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {unstable_batchedUpdates} from 'react-dom';
2+
3+
export default unstable_batchedUpdates;

0 commit comments

Comments
 (0)