You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's very common to need to rate-limit DOM events that fire too quickly, such as scroll or mousemove for performance reasons. In the ES5 world, it is very easy to create this kind of handler. For example, if you were using underscore:
However, in ES6 / TypeScript, the class syntax does not have a way to define a method based on the output of some function like this. You can still use the ES5 syntax, but that totally kills the hip vibe. Not to mention that this doesn't work for Dart at all.
We could solve this by introducing rate-limiters (or any of kind of similar function) for event handlers into Angular itself with a syntax something like:
These rate-limiters are needed by the material components, so it's only a question of whether Angular will support them directly or if the components have to roll our own rate limiting.
I think this should not be the concern of angular but rather of some third party plugin, as there could be lots of different ways you may want to limit this, and I would rather not get into this business. Also | is already used for pipe syntax so it can't be reused here.
Since there are few events that need to be handled this way (those are not really events, but rather continuous behaviors), I would prefer not to bake this mechanism into the framework unless we have to. Imo it should be done on a lower-level.
The only problem are zones. We don't want to trigger dirty checking when
the denouncing decides to ignore the event.
doing denouncing inside of an event handler in a directive or component
will always trigger change detection, as our event handlers run inside the
Angular zone.
So I think we need to think about this a little more...
@gdi2290 Hi Patrick, thanks but I basically want to try implement it by myself, if I will have troubles I would ask. If I use ChangeDetection.OnPush and Observables, I shouldn't worry about zoned change detections, am I correct ?
Please do this! This is a feature that is needed quite often
Reacted by CJ Mosure, Michael Sanford, Thomas Caserta, Orest Prystayko, David Dehghan, Mauro Mottini, swifmaneum, Lucas Bertola, digeomel, AnisTss and 1 more
Activity
mhevery commentedon May 13, 2015
@vsavkin Do you have an opinion?
I think this should not be the concern of angular but rather of some third party plugin, as there could be lots of different ways you may want to limit this, and I would rather not get into this business. Also
|is already used for pipe syntax so it can't be reused here.vsavkin commentedon May 13, 2015
Since there are few events that need to be handled this way (those are not really events, but rather continuous behaviors), I would prefer not to bake this mechanism into the framework unless we have to. Imo it should be done on a lower-level.
matanlurey commentedon May 14, 2015
Jeremy, couldn't you create a function at runtime in ES6, e.g.?
jelbourn commentedon May 14, 2015
The method has to be on the prototype, otherwise you're creating a copy of it for every component instance.
PatrickJS commentedon May 14, 2015
this is why decorators are awesome
tbosch commentedon May 14, 2015
The only problem are zones. We don't want to trigger dirty checking when
the denouncing decides to ignore the event.
doing denouncing inside of an event handler in a directive or component
will always trigger change detection, as our event handlers run inside the
Angular zone.
So I think we need to think about this a little more...
On Thu, May 14, 2015 at 7:27 AM PatrickJS notifications@github.com wrote:
jelbourn commentedon May 14, 2015
@tbosch that's a very good point
@vsavkin this kind of rate limiting is very common. Looking at the current material design components, some uses:
textareaelement)vicb commentedon May 14, 2015
If the implementation has not changed the event handler actually runs in the outer zone.
In the outer zone, we test if the event target is our actual element. Only when they match, we execute code in the angular zone which triggers the CD.
May be we can generalize the target = actual test with some more generic predicate support that would also work w/ debounce ?
33 remaining items
baio commentedon Jul 2, 2016
Hey guys any progress on this ?
PatrickJS commentedon Jul 2, 2016
@baio if you want this I can create a module for angular decorators that run outside of zone.js
baio commentedon Jul 2, 2016
@gdi2290 Hi Patrick, thanks but I basically want to try implement it by myself, if I will have troubles I would ask. If I use ChangeDetection.OnPush and Observables, I shouldn't worry about zoned change detections, am I correct ?
baio commentedon Jul 3, 2016
This is my attempt to implement this with decorator.
https://github.com/baio/link-shortener/blob/master/src/app/utils/debounce-decorator.ts
stalniy commentedon Sep 26, 2016
The most expected implementation would be to use
EVENT_MANAGER_PLUGINSmarkcooper commentedon Nov 14, 2016
Please do this! This is a feature that is needed quite often
andrevcf commentedon Jan 26, 2017
+1
mhevery commentedon Jan 28, 2017
Closing in favor of #13248, which will support this and many other use cases.
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.