@@ -11,6 +11,8 @@ import {
1111} from './ReactControlledComponent' ;
1212import { 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() {};
2830let batchedEventUpdatesImpl = batchedUpdatesImpl ;
2931
3032let isInsideEventHandler = false ;
33+ let isBatchingEventUpdates = false ;
3134
3235function finishEventHandler ( ) {
3336 // Here we wait until all updates have propagated, which is important
@@ -60,20 +63,31 @@ export function batchedUpdates(fn, bookkeeping) {
6063}
6164
6265export 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+
7791export function discreteUpdates ( fn , a , b , c ) {
7892 const prevIsInsideEventHandler = isInsideEventHandler ;
7993 isInsideEventHandler = true ;
0 commit comments