fix(core): should use native addEventListener in ngZone#20672
fix(core): should use native addEventListener in ngZone#20672JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Conversation
c2e7922 to
f9acbfe
Compare
404b3b5 to
b5bb8c1
Compare
|
This was reverted in ba850b3. It breaks automated testing because it changes whether the callback is invoked in the Zone. Needs more investigation. |
…)" This reverts commit 65a2cb8.
…lar#20672)" This reverts commit 65a2cb8.
b5bb8c1 to
1c50975
Compare
|
@mhevery , I have updated the PR.
please review. |
1c50975 to
904a324
Compare
There was a problem hiding this comment.
name is undefined - Meant to be eventName?
904a324 to
a39764c
Compare
|
@vikerman , thank you , I have changed the code, please review. |
6dc02ca to
f937c26
Compare
|
@JiaLiPassion @vikerman is on vacation until next week, so I don't think much will happen here. |
@mhevery , got it! thank you. |
|
@vikerman looking forward your review and merge 🤤 |
|
Hi @JiaLiPassion! This PR has merge conflicts due to recent upstream merges. |
17ceec1 to
74fc746
Compare
74fc746 to
b72eb90
Compare
|
Hi @JiaLiPassion! This PR has merge conflicts due to recent upstream merges. |
… listener. Close angular#19878 1. Can't pass `passive`, `capture`, `once` parameters to `addEventListener`. 2. Not easy to config use ngzone or noopzone with HostListener user need to explicitly call `runOutsideOfAngular` to make sure `eventhandler` run outsideof`ngZone` ``` @HostListener('window:resize', ['$event.target']) onResize(target: any) { this.ngZone.runOutsideOfAngular(() => { console.log('resize triggered'); }); } ``` or call `ngZone.run` explicitly make sure `eventhandler` run into `ngZone`. ``` @HostListener('window:resize', ['$event.target']) onResize(target: any) { this.ngZone.run(() => { console.log('resize triggered'); }); } ``` ``` <div (mouseover)="mouseover();"></div> ``` ``` mouseover() { this.ngZone.runOfAngular(() => { ... }); } ``` 3. Can config which `zone` will event handler will run into in `@HostListener` decorator. 4. can config `passive`, `capture`, `once` parameters to `addEventListener`. - in template, can config those parameter like below. ``` <div (mouseover.capture.once.passive)="mouseover();"></div> ``` even the handler was added not in `ngZone`. ``` <div (mouseover.ngZone)="mouseover();"></div> ``` ``` @HostListener('window:resize.ngZone', ['$event.target']) onResize(target: any) { console.log('resize triggered'); } ``` - Can config `noopZone` which will guarantee eventhandler run outside of `ngZone` even the handler was added in `ngZone`. And it can also work with angular#20672 to get better performance. ``` <div (mouseover.noopZone)="mouseover();"></div> ``` ``` @HostListener('window:resize.noopZone', ['$event.target']) onResize(target: any) { console.log('resize triggered'); } ```
… listener. Close angular#19878 1. Can't pass `passive`, `capture`, `once` parameters to `addEventListener`. 2. Not easy to config use ngzone or noopzone with HostListener user need to explicitly call `runOutsideOfAngular` to make sure `eventhandler` run outsideof`ngZone` ``` @HostListener('window:resize', ['$event.target']) onResize(target: any) { this.ngZone.runOutsideOfAngular(() => { console.log('resize triggered'); }); } ``` or call `ngZone.run` explicitly make sure `eventhandler` run into `ngZone`. ``` @HostListener('window:resize', ['$event.target']) onResize(target: any) { this.ngZone.run(() => { console.log('resize triggered'); }); } ``` ``` <div (mouseover)="mouseover();"></div> ``` ``` mouseover() { this.ngZone.runOfAngular(() => { ... }); } ``` 3. Can config which `zone` will event handler will run into in `@HostListener` decorator. 4. can config `passive`, `capture`, `once` parameters to `addEventListener`. - in template, can config those parameter like below. ``` <div (mouseover.capture.once.passive)="mouseover();"></div> ``` even the handler was added not in `ngZone`. ``` <div (mouseover.ngZone)="mouseover();"></div> ``` ``` @HostListener('window:resize.ngZone', ['$event.target']) onResize(target: any) { console.log('resize triggered'); } ``` - Can config `noopZone` which will guarantee eventhandler run outside of `ngZone` even the handler was added in `ngZone`. And it can also work with angular#20672 to get better performance. ``` <div (mouseover.noopZone)="mouseover();"></div> ``` ``` @HostListener('window:resize.noopZone', ['$event.target']) onResize(target: any) { console.log('resize triggered'); } ```
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: 20673
fix #20673
in #18993, there is an optimized version of
addEventListener, but I used the wrongaddEventListenerwhen we run inngZone, we should use nativeaddEventListenerto get better performance when the handler was added inngZone.And the other issue is in #18993, we support
BLACK_LISTED_EVENTS, and if an event is blacklisted, it should not run inangularzone, but current version it will not work.What is the new behavior?
When event handler was added in
angular zone, usenon patchedaddEventListener to get better performance.And
BLACK_LISTED_EVENTSshould work and run outside of angular zone.Does this PR introduce a breaking change?
Other information
@mhevery , please review, thank you!