Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dce430a

Browse files
authored
[Flare] Rework the responder dispatching/batching mechanism (facebook#16334)
1 parent 6ae6a7c commit dce430a

File tree

15 files changed

+149
-565
lines changed

15 files changed

+149
-565
lines changed

packages/legacy-events/ReactGenericBatching.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
} from './ReactControlledComponent';
1212
import {enableFlareAPI} from 'shared/ReactFeatureFlags';
1313

14+
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
15+
1416
// Used as a way to call batchedUpdates when we don't have a reference to
1517
// the renderer. Such as when we're dispatching events or if third party
1618
// libraries need to call batchedUpdates. Eventually, this API will go away when
@@ -28,6 +30,7 @@ let flushDiscreteUpdatesImpl = function() {};
2830
let batchedEventUpdatesImpl = batchedUpdatesImpl;
2931

3032
let isInsideEventHandler = false;
33+
let isBatchingEventUpdates = false;
3134

3235
function finishEventHandler() {
3336
// Here we wait until all updates have propagated, which is important
@@ -60,20 +63,31 @@ export function batchedUpdates(fn, bookkeeping) {
6063
}
6164

6265
export function batchedEventUpdates(fn, a, b) {
63-
if (isInsideEventHandler) {
66+
if (isBatchingEventUpdates) {
6467
// If we are currently inside another batch, we need to wait until it
6568
// fully completes before restoring state.
6669
return fn(a, b);
6770
}
68-
isInsideEventHandler = true;
71+
isBatchingEventUpdates = true;
6972
try {
7073
return batchedEventUpdatesImpl(fn, a, b);
7174
} finally {
72-
isInsideEventHandler = false;
75+
isBatchingEventUpdates = false;
7376
finishEventHandler();
7477
}
7578
}
7679

80+
export function executeUserEventHandler(fn: any => void, value: any) {
81+
const previouslyInEventHandler = isInsideEventHandler;
82+
try {
83+
isInsideEventHandler = true;
84+
const type = typeof value === 'object' && value !== null ? value.type : '';
85+
invokeGuardedCallbackAndCatchFirstError(type, fn, undefined, value);
86+
} finally {
87+
isInsideEventHandler = previouslyInEventHandler;
88+
}
89+
}
90+
7791
export function discreteUpdates(fn, a, b, c) {
7892
const prevIsInsideEventHandler = isInsideEventHandler;
7993
isInsideEventHandler = true;

0 commit comments

Comments
 (0)