@@ -11,6 +11,8 @@ import {
11
11
} from './ReactControlledComponent' ;
12
12
import { enableFlareAPI } from 'shared/ReactFeatureFlags' ;
13
13
14
+ import { invokeGuardedCallbackAndCatchFirstError } from 'shared/ReactErrorUtils' ;
15
+
14
16
// Used as a way to call batchedUpdates when we don't have a reference to
15
17
// the renderer. Such as when we're dispatching events or if third party
16
18
// libraries need to call batchedUpdates. Eventually, this API will go away when
@@ -28,6 +30,7 @@ let flushDiscreteUpdatesImpl = function() {};
28
30
let batchedEventUpdatesImpl = batchedUpdatesImpl ;
29
31
30
32
let isInsideEventHandler = false ;
33
+ let isBatchingEventUpdates = false ;
31
34
32
35
function finishEventHandler ( ) {
33
36
// Here we wait until all updates have propagated, which is important
@@ -60,20 +63,31 @@ export function batchedUpdates(fn, bookkeeping) {
60
63
}
61
64
62
65
export function batchedEventUpdates ( fn , a , b ) {
63
- if ( isInsideEventHandler ) {
66
+ if ( isBatchingEventUpdates ) {
64
67
// If we are currently inside another batch, we need to wait until it
65
68
// fully completes before restoring state.
66
69
return fn ( a , b ) ;
67
70
}
68
- isInsideEventHandler = true ;
71
+ isBatchingEventUpdates = true ;
69
72
try {
70
73
return batchedEventUpdatesImpl ( fn , a , b ) ;
71
74
} finally {
72
- isInsideEventHandler = false ;
75
+ isBatchingEventUpdates = false ;
73
76
finishEventHandler ( ) ;
74
77
}
75
78
}
76
79
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
+
77
91
export function discreteUpdates ( fn , a , b , c ) {
78
92
const prevIsInsideEventHandler = isInsideEventHandler ;
79
93
isInsideEventHandler = true ;
0 commit comments