Proposal: declaring rate-limited event handlers (debounce, throttle)
See original GitHub issueIt’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:
<widget (movemove)="checkHoverPosition($event)">
Widget.prototype.checkHoverPosition = _.debounce(function(event) {
// ...
}, 300);
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:
<widget (movemove)="checkHoverPosition($event) | debounce:300">
<widget (movemove)="checkHoverPosition($event) | throttle:300">
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.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:12
- Comments:36 (24 by maintainers)
Please do this! This is a feature that is needed quite often
+1