@@ -10,6 +10,7 @@ import {
1010 hasDispatches ,
1111 executeDispatchesInOrderStopAtTrue ,
1212 getInstanceFromNode ,
13+ getFiberCurrentPropsFromNode ,
1314} from './EventPluginUtils' ;
1415import ResponderSyntheticEvent from './ResponderSyntheticEvent' ;
1516import ResponderTouchHistoryStore from './ResponderTouchHistoryStore' ;
@@ -25,10 +26,10 @@ import {
2526 moveDependencies ,
2627 endDependencies ,
2728} from './ResponderTopLevelEventTypes' ;
28- import getListener from './getListener' ;
2929import accumulateInto from './accumulateInto' ;
3030import forEachAccumulated from './forEachAccumulated' ;
3131import { HostComponent } from 'react-reconciler/src/ReactWorkTags' ;
32+ import invariant from 'shared/invariant' ;
3233
3334/**
3435 * Instance of element that should respond to touch/move types of interactions,
@@ -208,7 +209,7 @@ export function getLowestCommonAncestor(instA, instB) {
208209/**
209210 * Return if A is an ancestor of B.
210211 */
211- export function isAncestor ( instA , instB ) {
212+ function isAncestor ( instA , instB ) {
212213 while ( instB ) {
213214 if ( instA === instB || instA === instB . alternate ) {
214215 return true ;
@@ -221,7 +222,7 @@ export function isAncestor(instA, instB) {
221222/**
222223 * Simulates the traversal of a two-phase, capture/bubble event dispatch.
223224 */
224- export function traverseTwoPhase ( inst , fn , arg ) {
225+ function traverseTwoPhase ( inst , fn , arg ) {
225226 const path = [ ] ;
226227 while ( inst ) {
227228 path . push ( inst ) ;
@@ -236,6 +237,27 @@ export function traverseTwoPhase(inst, fn, arg) {
236237 }
237238}
238239
240+ function getListener ( inst , registrationName ) {
241+ const stateNode = inst . stateNode ;
242+ if ( stateNode === null ) {
243+ // Work in progress (ex: onload events in incremental mode).
244+ return null ;
245+ }
246+ const props = getFiberCurrentPropsFromNode ( stateNode ) ;
247+ if ( props === null ) {
248+ // Work in progress.
249+ return null ;
250+ }
251+ const listener = props [ registrationName ] ;
252+ invariant (
253+ ! listener || typeof listener === 'function' ,
254+ 'Expected `%s` listener to be a function, instead got a value of `%s` type.' ,
255+ registrationName ,
256+ typeof listener ,
257+ ) ;
258+ return listener ;
259+ }
260+
239261function listenerAtPhase ( inst , event , propagationPhase : PropagationPhases ) {
240262 const registrationName =
241263 event . dispatchConfig . phasedRegistrationNames [ propagationPhase ] ;
0 commit comments