-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP(compiler): fix #19878, can config zone/once/passive/capture in template/HostListener decorator #21681
Conversation
@JiaLiPassion I use custom |
@devoto13, thank you for the information. It is the same idea, and |
Wouldn't be a "true" or "false" be simpler? |
@ericmartinezr , yeah, I use |
32aec18
to
3fc9264
Compare
ceb3984
to
62e59a4
Compare
I just saw the discussion here, #11200.
There are lot of options need to be extended in the future.
I am not sure which design is better.
<button (click: {passive: true})="onClick($event)"></button>
~click => capture: true
-scroll=> passive: true
#scroll=> zone: ngzone
$scroll=> zone: nozone I prefer the second one, the first one need user to write more code and will need to modify more codes of @mhevery , please review, and I will try to modify this PR with the second one first to see is there any risk, thank you. |
/cc @IgorMinar It would be great if you add your opinion.
What I have in mind is something like this.
I am open for suggestions as how to make it better... What do you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just skimmed through and I'm not sure yet if we want to do this at all, but if we do go forward, we should change the api to use an object literal config object rather than string literal. This would allow us to also support passive listeners (see #8866) and other options.
I'll review this in more detail next week, just wanted to provide quick feedback on the API. |
@IgorMinar I agree that current implementation is not what we want, but what about my proposal as described in the comment #21681 (comment) |
@mhevery , @IgorMinar , thank you for the review.
Yes, you are right, I forget we already have the syntax like
is a better and consistent solution. |
@mhevery , @IgorMinar , I have updated this PR, it is still basically the options below can be configured.
And those options can be configured in
<div (mouseover.capture.once.passive)="mouseover();"></div>
@HostListener('window:resize.nozone', ['$event.target'])
onResize(target: any) {
console.log('resize triggered');
} The order of The current PR will have to wait for a PR of |
…ve in HostListener decorator
Hi @JiaLiPassion! This PR has merge conflicts due to recent upstream merges. |
@JiaLiPassion Is it the case that it's assumed passive is false unless included in the list? Per https://bugs.webkit.org/show_bug.cgi?id=182521#c3 (causing issues like mapbox/mapbox-gl-js#6095 -- not an Angular project but illustrates why some apps are broken) it is now the case that it defaults to true on window and document events. Thus, users may explicitly need to configure it to be false in some cases. |
@okhobb , thank you for the information, I will check it the situation when event such as |
This is something I would really like to be able to use. Is there any news on whether or not .nozone, .ngzone, and the like will implemented? |
Hi, Any new updates on this ? This feature is very nice and useful for developers. |
Close this one and open a new PR #38236 |
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: #19878
can't pass
passive
,capture
,once
parameters toaddEventListener
.not easy to config use ngzone or nozone with HostListener
user need to explicitly call
runOutsideOfAngular
to make sureeventhandler
run outsideofngZone
or call
ngZone.run
explicitly make sureeventhandler
run intongZone
.not easy to run event handler outsideOfAngular in template
What is the new behavior?
Can config which
zone
will event handler will run into in@HostListener
decorator.can config
passive
,capture
,once
parameters toaddEventListener
.can config
ngzone
which will guarantee eventhandler run inngZone
even the handler wasadded not in
ngZone
.nozone
which will guarantee eventhandler run outside ofngZone
even the handler was added inngZone
. and if configoutsideOfAngular
, DOMEventManager will bypass zone.js and directly use native addEventListener to improve performance.And it can also work with #20672 to get better performance.
Does this PR introduce a breaking change?
Other information