@@ -709,31 +709,19 @@ function createDispatchListener(
709709 } ;
710710}
711711
712- function createDispatchEntry (
713- event : ReactSyntheticEvent ,
714- listeners : Array < DispatchListener > ,
715- ) : DispatchEntry {
716- return {
717- event,
718- listeners,
719- } ;
720- }
721-
722712export function accumulateSinglePhaseListeners (
723713 targetFiber : Fiber | null ,
724- dispatchQueue : DispatchQueue ,
725- event : ReactSyntheticEvent ,
714+ reactName : string | null ,
715+ nativeEventType : string ,
726716 inCapturePhase : boolean ,
727717 accumulateTargetOnly : boolean ,
728- ) : void {
729- const bubbleName = event . _reactName ;
730- const captureName = bubbleName !== null ? bubbleName + 'Capture' : null ;
731- const reactEventName = inCapturePhase ? captureName : bubbleName ;
718+ ) : Array < DispatchListener > {
719+ const captureName = reactName !== null ? reactName + 'Capture' : null ;
720+ const reactEventName = inCapturePhase ? captureName : reactName ;
732721 const listeners : Array < DispatchListener > = [];
733722
734723 let instance = targetFiber;
735724 let lastHostComponent = null;
736- const targetType = event.nativeEvent.type;
737725
738726 // Accumulate all instances and listeners via the target -> root path .
739727 while ( instance !== null ) {
@@ -749,7 +737,10 @@ export function accumulateSinglePhaseListeners(
749737 ) ;
750738 if ( eventHandlerListeners !== null ) {
751739 eventHandlerListeners . forEach ( entry => {
752- if ( entry . type === targetType && entry . capture === inCapturePhase ) {
740+ if (
741+ entry . type === nativeEventType &&
742+ entry . capture === inCapturePhase
743+ ) {
753744 listeners . push (
754745 createDispatchListener (
755746 instance ,
@@ -785,7 +776,10 @@ export function accumulateSinglePhaseListeners(
785776 ) ;
786777 if ( eventHandlerListeners !== null ) {
787778 eventHandlerListeners . forEach ( entry => {
788- if ( entry . type === targetType && entry . capture === inCapturePhase ) {
779+ if (
780+ entry . type === nativeEventType &&
781+ entry . capture === inCapturePhase
782+ ) {
789783 listeners . push (
790784 createDispatchListener (
791785 instance ,
@@ -805,9 +799,7 @@ export function accumulateSinglePhaseListeners(
805799 }
806800 instance = instance . return ;
807801 }
808- if ( listeners . length !== 0 ) {
809- dispatchQueue . push ( createDispatchEntry ( event , listeners ) ) ;
810- }
802+ return listeners ;
811803}
812804
813805// We should only use this function for:
@@ -819,11 +811,9 @@ export function accumulateSinglePhaseListeners(
819811// phase event listeners (via emulation).
820812export function accumulateTwoPhaseListeners (
821813 targetFiber : Fiber | null ,
822- dispatchQueue : DispatchQueue ,
823- event : ReactSyntheticEvent ,
824- ) : void {
825- const bubbleName = event . _reactName ;
826- const captureName = bubbleName !== null ? bubbleName + 'Capture' : null ;
814+ reactName : string ,
815+ ) : Array < DispatchListener > {
816+ const captureName = reactName + 'Capture' ;
827817 const listeners : Array < DispatchListener > = [ ] ;
828818 let instance = targetFiber ;
829819
@@ -833,29 +823,22 @@ export function accumulateTwoPhaseListeners(
833823 // Handle listeners that are on HostComponents (i.e. <div>)
834824 if ( tag === HostComponent && stateNode !== null ) {
835825 const currentTarget = stateNode ;
836- // Standard React on* listeners, i.e. onClick prop
837- if ( captureName !== null ) {
838- const captureListener = getListener ( instance , captureName ) ;
839- if ( captureListener != null ) {
840- listeners . unshift (
841- createDispatchListener ( instance , captureListener , currentTarget ) ,
842- ) ;
843- }
826+ const captureListener = getListener ( instance , captureName ) ;
827+ if ( captureListener != null ) {
828+ listeners . unshift (
829+ createDispatchListener ( instance , captureListener , currentTarget ) ,
830+ ) ;
844831 }
845- if ( bubbleName !== null ) {
846- const bubbleListener = getListener ( instance , bubbleName ) ;
847- if ( bubbleListener != null ) {
848- listeners . push (
849- createDispatchListener ( instance , bubbleListener , currentTarget ) ,
850- ) ;
851- }
832+ const bubbleListener = getListener ( instance , reactName ) ;
833+ if ( bubbleListener != null ) {
834+ listeners . push (
835+ createDispatchListener ( instance , bubbleListener , currentTarget ) ,
836+ ) ;
852837 }
853838 }
854839 instance = instance . return ;
855840 }
856- if ( listeners . length !== 0 ) {
857- dispatchQueue . push ( createDispatchEntry ( event , listeners ) ) ;
858- }
841+ return listeners ;
859842}
860843
861844function getParent ( inst : Fiber | null ) : Fiber | null {
@@ -956,7 +939,7 @@ function accumulateEnterLeaveListenersForEvent(
956939 instance = instance . return ;
957940 }
958941 if ( listeners . length !== 0 ) {
959- dispatchQueue . push ( createDispatchEntry ( event , listeners ) ) ;
942+ dispatchQueue . push ( { event, listeners} ) ;
960943 }
961944}
962945
@@ -995,27 +978,23 @@ export function accumulateEnterLeaveTwoPhaseListeners(
995978}
996979
997980export function accumulateEventHandleNonManagedNodeListeners (
998- dispatchQueue : DispatchQueue ,
999- event : ReactSyntheticEvent ,
981+ reactEventType : DOMEventName ,
1000982 currentTarget : EventTarget ,
1001983 inCapturePhase : boolean ,
1002- ) : void {
984+ ) : Array < DispatchListener > {
1003985 const listeners : Array < DispatchListener > = [ ] ;
1004986
1005987 const eventListeners = getEventHandlerListeners ( currentTarget ) ;
1006988 if ( eventListeners !== null ) {
1007- const targetType = ( ( event . type : any ) : DOMEventName ) ;
1008989 eventListeners . forEach ( entry => {
1009- if ( entry . type === targetType && entry . capture === inCapturePhase ) {
990+ if ( entry . type === reactEventType && entry . capture === inCapturePhase ) {
1010991 listeners . push (
1011992 createDispatchListener ( null , entry . callback , currentTarget ) ,
1012993 ) ;
1013994 }
1014995 } ) ;
1015996 }
1016- if ( listeners . length !== 0 ) {
1017- dispatchQueue . push ( createDispatchEntry ( event , listeners ) ) ;
1018- }
997+ return listeners ;
1019998}
1020999
10211000export function getListenerSetKey (
0 commit comments