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.
Andrew Clark committed
Jun 30, 2021 at 14:29 UTC
ae5afb3b9d347636037b69222c0534d4187b05ab
1 file changed
+11
-30
packages/react-dom/src/events/ReactDOMUpdateBatching.js
+11
-30
@@ -24,10 +24,11 @@ let discreteUpdatesImpl = function(fn, a, b, c, d) {
24
return fn(a, b, c, d);
25
};
26
let flushDiscreteUpdatesImpl = function() {};
27
-let batchedEventUpdatesImpl = batchedUpdatesImpl;
27
+// TODO: Remove references to batchedEventUpdates
28
+// let batchedEventUpdatesImpl = batchedUpdatesImpl;
29
30
let isInsideEventHandler = false;
30
-let isBatchingEventUpdates = false;
31
+// let isBatchingEventUpdates = false;
32
33
function finishEventHandler() {
34
// Here we wait until all updates have propagated, which is important
@@ -46,48 +47,27 @@ function finishEventHandler() {
47
}
48
}
49
49
-export function batchedUpdates(fn, bookkeeping) {
50
+export function batchedUpdates(fn, a, b) {
51
if (isInsideEventHandler) {
52
// If we are currently inside another batch, we need to wait until it
53
// fully completes before restoring state.
53
- return fn(bookkeeping);
54
+ return fn(a, b);
55
}
56
isInsideEventHandler = true;
57
try {
57
- return batchedUpdatesImpl(fn, bookkeeping);
58
+ return batchedUpdatesImpl(fn, a, b);
59
} finally {
60
isInsideEventHandler = false;
61
finishEventHandler();
62
}
63
}
64
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;
67
68
// TODO: Replace with flushSync
69
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);
71
}
72
73
export function setBatchingImplementation(
@@ -99,5 +79,6 @@ export function setBatchingImplementation(
79
batchedUpdatesImpl = _batchedUpdatesImpl;
80
discreteUpdatesImpl = _discreteUpdatesImpl;
81
flushDiscreteUpdatesImpl = _flushDiscreteUpdatesImpl;
102
- batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
82
+ // TODO: Remove references to batchedEventUpdates
83
+ // batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
84
}