This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,7 +115,8 @@ function patchEventTargetMethods(obj) {
115115
116116 handler [ originalFnKey ] = fn ;
117117 handler [ boundFnsKey ] = handler [ boundFnsKey ] || { } ;
118- arguments [ 1 ] = handler [ boundFnsKey ] [ eventType ] = zone . bind ( fn ) ;
118+ handler [ boundFnsKey ] [ eventType ] = handler [ boundFnsKey ] [ eventType ] || zone . bind ( fn ) ;
119+ arguments [ 1 ] = handler [ boundFnsKey ] [ eventType ] ;
119120 }
120121 return global . zone . addEventListener . apply ( this , arguments ) ;
121122 } ;
Original file line number Diff line number Diff line change @@ -84,6 +84,32 @@ describe('element', function () {
8484 expect ( eventListener . handleEvent ) . not . toHaveBeenCalled ( ) ;
8585 } ) ;
8686
87+
88+ it ( 'should only add a listener once for a given set of arguments' , function ( ) {
89+ var log = [ ] ;
90+ var clickEvent = document . createEvent ( 'Event' ) ;
91+
92+ function listener ( ) {
93+ log . push ( 'listener' ) ;
94+ }
95+
96+ clickEvent . initEvent ( 'click' , true , true ) ;
97+
98+ button . addEventListener ( 'click' , listener ) ;
99+ button . addEventListener ( 'click' , listener ) ;
100+ button . addEventListener ( 'click' , listener ) ;
101+
102+ button . dispatchEvent ( clickEvent ) ;
103+
104+ button . removeEventListener ( 'click' , listener ) ;
105+
106+ button . dispatchEvent ( clickEvent ) ;
107+
108+ expect ( log ) . toEqual ( [
109+ 'listener'
110+ ] ) ;
111+ } ) ;
112+
87113 it ( 'should correctly handle capturing versus nonCapturing eventListeners' , function ( ) {
88114 var log = [ ] ;
89115 var clickEvent = document . createEvent ( 'Event' ) ;
You can’t perform that action at this time.
0 commit comments