Skip to content

Files

Latest commit

 

History

History
18 lines (15 loc) · 1.51 KB

4.md

File metadata and controls

18 lines (15 loc) · 1.51 KB
title date submitter number tags discussion
I want a standard API for event throttling and debouncing
2019-06-24 00:00:00 UTC
Šime Vidas
4
javascript

There are numerous events in JavaScript that can get triggered repeatedly, necessitating that developers write additional code to throttle these events. For example:

  • The Network Information API change event fires whenever a network change occurs, but this can happen in rapid succession when users pass through tunnels or move from WiFi to a cellular network. In almost all use cases, only the last event in the series is truly relevant.
  • The resize event is fired repeatedly when a window corner is dragged to resize the browser application. In almost all cases, a developer who wants to know when a resize has occurred—so they can adjust the user experience in a responsive context—only cares about the final event.
  • The change event on an input fires repeatedly when a user is typing, but for expensive operations like API lookups based on the entered content, developers will only want to trigger the API call when the user pauses for a bit or stops typing altogether.
  • The mousemove event fires much faster than movement is perceivable by the human eye, so it would be useful to be able to throttle it to a lower frequency (e.g., 20 Hz).

I want a native way to configure these (and similar) events to fire less frequently without having to write the debouncing and throttling code myself.