Skip to content

Commit ae5afb3

Browse files
authored
Simplify discreteUpdates (#21773)
Now that discrete updates are flushed synchronously in a microtask, the `discreteUpdates` method used by our event system is only a optimization to save us from having to check `window.event.type` on every update. So we should be able to remove the extra logic. Assuming this lands successfully, we can remove `batchedEventUpdates` and probably inline `discreteUpdates` into the renderer, like we do for continuous updates.
1 parent 3e8c86c commit ae5afb3

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

packages/react-dom/src/events/ReactDOMUpdateBatching.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ let discreteUpdatesImpl = function(fn, a, b, c, d) {
2424
return fn(a, b, c, d);
2525
};
2626
let flushDiscreteUpdatesImpl = function() {};
27-
let batchedEventUpdatesImpl = batchedUpdatesImpl;
27+
// TODO: Remove references to batchedEventUpdates
28+
// let batchedEventUpdatesImpl = batchedUpdatesImpl;
2829

2930
let isInsideEventHandler = false;
30-
let isBatchingEventUpdates = false;
31+
// let isBatchingEventUpdates = false;
3132

3233
function finishEventHandler() {
3334
// Here we wait until all updates have propagated, which is important
@@ -46,48 +47,27 @@ function finishEventHandler() {
4647
}
4748
}
4849

49-
export function batchedUpdates(fn, bookkeeping) {
50+
export function batchedUpdates(fn, a, b) {
5051
if (isInsideEventHandler) {
5152
// If we are currently inside another batch, we need to wait until it
5253
// fully completes before restoring state.
53-
return fn(bookkeeping);
54+
return fn(a, b);
5455
}
5556
isInsideEventHandler = true;
5657
try {
57-
return batchedUpdatesImpl(fn, bookkeeping);
58+
return batchedUpdatesImpl(fn, a, b);
5859
} finally {
5960
isInsideEventHandler = false;
6061
finishEventHandler();
6162
}
6263
}
6364

64-
export function batchedEventUpdates(fn, a, b) {
65-
if (isBatchingEventUpdates) {
66-
// If we are currently inside another batch, we need to wait until it
67-
// fully completes before restoring state.
68-
return fn(a, b);
69-
}
70-
isBatchingEventUpdates = true;
71-
try {
72-
return batchedEventUpdatesImpl(fn, a, b);
73-
} finally {
74-
isBatchingEventUpdates = false;
75-
finishEventHandler();
76-
}
77-
}
65+
// TODO: Remove references to batchedEventUpdates
66+
export const batchedEventUpdates = batchedUpdates;
7867

7968
// TODO: Replace with flushSync
8069
export function discreteUpdates(fn, a, b, c, d) {
81-
const prevIsInsideEventHandler = isInsideEventHandler;
82-
isInsideEventHandler = true;
83-
try {
84-
return discreteUpdatesImpl(fn, a, b, c, d);
85-
} finally {
86-
isInsideEventHandler = prevIsInsideEventHandler;
87-
if (!isInsideEventHandler) {
88-
finishEventHandler();
89-
}
90-
}
70+
return discreteUpdatesImpl(fn, a, b, c, d);
9171
}
9272

9373
export function setBatchingImplementation(
@@ -99,5 +79,6 @@ export function setBatchingImplementation(
9979
batchedUpdatesImpl = _batchedUpdatesImpl;
10080
discreteUpdatesImpl = _discreteUpdatesImpl;
10181
flushDiscreteUpdatesImpl = _flushDiscreteUpdatesImpl;
102-
batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
82+
// TODO: Remove references to batchedEventUpdates
83+
// batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
10384
}

0 commit comments

Comments
 (0)