@@ -726,8 +726,9 @@ export function accumulateSinglePhaseListeners(
726
726
inCapturePhase : boolean ,
727
727
accumulateTargetOnly : boolean ,
728
728
) : void {
729
- const bubbled = event . _reactName ;
730
- const captured = bubbled !== null ? bubbled + 'Capture' : null ;
729
+ const bubbleName = event . _reactName ;
730
+ const captureName = bubbleName !== null ? bubbleName + 'Capture' : null ;
731
+ const reactEventName = inCapturePhase ? captureName : bubbleName ;
731
732
const listeners : Array < DispatchListener > = [];
732
733
733
734
let instance = targetFiber;
@@ -739,48 +740,34 @@ export function accumulateSinglePhaseListeners(
739
740
const { stateNode, tag} = instance ;
740
741
// Handle listeners that are on HostComponents (i.e. <div>)
741
742
if ( tag === HostComponent && stateNode !== null ) {
742
- const currentTarget = stateNode ;
743
- lastHostComponent = currentTarget ;
744
- // For Event Handle listeners
745
- if ( enableCreateEventHandleAPI ) {
746
- const eventHandlerlisteners = getEventHandlerListeners ( currentTarget ) ;
743
+ lastHostComponent = stateNode ;
747
744
748
- if ( eventHandlerlisteners !== null ) {
749
- const eventHandlerlistenersArr = Array . from ( eventHandlerlisteners ) ;
750
- for ( let i = 0 ; i < eventHandlerlistenersArr . length ; i ++ ) {
751
- const {
752
- callback,
753
- capture : isCapturePhaseListener ,
754
- type,
755
- } = eventHandlerlistenersArr [ i ] ;
756
- if ( type === targetType ) {
757
- if ( isCapturePhaseListener && inCapturePhase ) {
758
- listeners . push (
759
- createDispatchListener ( instance , callback , currentTarget ) ,
760
- ) ;
761
- } else if ( ! isCapturePhaseListener && ! inCapturePhase ) {
762
- listeners . push (
763
- createDispatchListener ( instance , callback , currentTarget ) ,
764
- ) ;
765
- }
745
+ // createEventHandle listeners
746
+ if ( enableCreateEventHandleAPI ) {
747
+ const eventHandlerListeners = getEventHandlerListeners (
748
+ lastHostComponent ,
749
+ ) ;
750
+ if ( eventHandlerListeners !== null ) {
751
+ eventHandlerListeners . forEach ( entry => {
752
+ if ( entry . type === targetType && entry . capture === inCapturePhase ) {
753
+ listeners . push (
754
+ createDispatchListener (
755
+ instance ,
756
+ entry . callback ,
757
+ ( lastHostComponent : any ) ,
758
+ ) ,
759
+ ) ;
766
760
}
767
- }
768
- }
769
- }
770
- // Standard React on* listeners, i.e. onClick prop
771
- if ( captured !== null && inCapturePhase ) {
772
- const captureListener = getListener ( instance , captured ) ;
773
- if ( captureListener != null ) {
774
- listeners . push (
775
- createDispatchListener ( instance , captureListener , currentTarget ) ,
776
- ) ;
761
+ } ) ;
777
762
}
778
763
}
779
- if ( bubbled !== null && ! inCapturePhase ) {
780
- const bubbleListener = getListener ( instance , bubbled ) ;
781
- if ( bubbleListener != null ) {
764
+
765
+ // Standard React on* listeners, i.e. onClick or onClickCapture
766
+ if ( reactEventName !== null ) {
767
+ const listener = getListener ( instance , reactEventName ) ;
768
+ if ( listener != null ) {
782
769
listeners . push (
783
- createDispatchListener ( instance , bubbleListener , currentTarget ) ,
770
+ createDispatchListener ( instance , listener , lastHostComponent ) ,
784
771
) ;
785
772
}
786
773
}
@@ -791,32 +778,23 @@ export function accumulateSinglePhaseListeners(
791
778
lastHostComponent !== null &&
792
779
stateNode !== null
793
780
) {
781
+ // Scopes
794
782
const reactScopeInstance = stateNode ;
795
- const eventHandlerlisteners = getEventHandlerListeners (
783
+ const eventHandlerListeners = getEventHandlerListeners (
796
784
reactScopeInstance ,
797
785
) ;
798
- const lastCurrentTarget = ( ( lastHostComponent : any ) : Element ) ;
799
-
800
- if ( eventHandlerlisteners !== null ) {
801
- const eventHandlerlistenersArr = Array . from ( eventHandlerlisteners ) ;
802
- for ( let i = 0 ; i < eventHandlerlistenersArr . length ; i ++ ) {
803
- const {
804
- callback,
805
- capture : isCapturePhaseListener ,
806
- type,
807
- } = eventHandlerlistenersArr [ i ] ;
808
- if ( type === targetType ) {
809
- if ( isCapturePhaseListener && inCapturePhase ) {
810
- listeners . push (
811
- createDispatchListener ( instance , callback , lastCurrentTarget ) ,
812
- ) ;
813
- } else if ( ! isCapturePhaseListener && ! inCapturePhase ) {
814
- listeners . push (
815
- createDispatchListener ( instance , callback , lastCurrentTarget ) ,
816
- ) ;
817
- }
786
+ if ( eventHandlerListeners !== null ) {
787
+ eventHandlerListeners . forEach ( entry => {
788
+ if ( entry . type === targetType && entry . capture === inCapturePhase ) {
789
+ listeners . push (
790
+ createDispatchListener (
791
+ instance ,
792
+ entry . callback ,
793
+ ( lastHostComponent : any ) ,
794
+ ) ,
795
+ ) ;
818
796
}
819
- }
797
+ } ) ;
820
798
}
821
799
}
822
800
// If we are only accumulating events for the target, then we don't
@@ -844,8 +822,8 @@ export function accumulateTwoPhaseListeners(
844
822
dispatchQueue : DispatchQueue ,
845
823
event : ReactSyntheticEvent ,
846
824
) : void {
847
- const bubbled = event . _reactName ;
848
- const captured = bubbled !== null ? bubbled + 'Capture' : null ;
825
+ const bubbleName = event . _reactName ;
826
+ const captureName = bubbleName !== null ? bubbleName + 'Capture' : null ;
849
827
const listeners : Array < DispatchListener > = [ ] ;
850
828
let instance = targetFiber ;
851
829
@@ -856,16 +834,16 @@ export function accumulateTwoPhaseListeners(
856
834
if ( tag === HostComponent && stateNode !== null ) {
857
835
const currentTarget = stateNode ;
858
836
// Standard React on* listeners, i.e. onClick prop
859
- if ( captured !== null ) {
860
- const captureListener = getListener ( instance , captured ) ;
837
+ if ( captureName !== null ) {
838
+ const captureListener = getListener ( instance , captureName ) ;
861
839
if ( captureListener != null ) {
862
840
listeners . unshift (
863
841
createDispatchListener ( instance , captureListener , currentTarget ) ,
864
842
) ;
865
843
}
866
844
}
867
- if ( bubbled !== null ) {
868
- const bubbleListener = getListener ( instance , bubbled ) ;
845
+ if ( bubbleName !== null ) {
846
+ const bubbleListener = getListener ( instance , bubbleName ) ;
869
847
if ( bubbleListener != null ) {
870
848
listeners . push (
871
849
createDispatchListener ( instance , bubbleListener , currentTarget ) ,
@@ -1026,20 +1004,14 @@ export function accumulateEventHandleNonManagedNodeListeners(
1026
1004
1027
1005
const eventListeners = getEventHandlerListeners ( currentTarget ) ;
1028
1006
if ( eventListeners !== null ) {
1029
- const listenersArr = Array . from ( eventListeners ) ;
1030
1007
const targetType = ( ( event . type : any ) : DOMEventName ) ;
1031
-
1032
- for ( let i = 0 ; i < listenersArr . length ; i ++ ) {
1033
- const listener = listenersArr [ i ] ;
1034
- const { callback , capture : isCapturePhaseListener , type } = listener ;
1035
- if ( type === targetType ) {
1036
- if ( inCapturePhase && isCapturePhaseListener ) {
1037
- listeners . push ( createDispatchListener ( null , callback , currentTarget ) ) ;
1038
- } else if ( ! inCapturePhase && ! isCapturePhaseListener ) {
1039
- listeners . push ( createDispatchListener ( null , callback , currentTarget ) ) ;
1040
- }
1008
+ eventListeners . forEach ( entry => {
1009
+ if ( entry . type === targetType && entry . capture === inCapturePhase ) {
1010
+ listeners . push (
1011
+ createDispatchListener ( null , entry . callback , currentTarget ) ,
1012
+ ) ;
1041
1013
}
1042
- }
1014
+ } ) ;
1043
1015
}
1044
1016
if ( listeners . length !== 0 ) {
1045
1017
dispatchQueue . push ( createDispatchEntry ( event , listeners ) ) ;
0 commit comments