jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.29k stars 5.53k forks source link

Run debounce() callback if browser tab is closed #2983

Closed h closed 1 year ago

h commented 1 year ago

There's common problem with debounced API calls: when the user closes the browser tab, the debounced function may not have run yet. This is a frequent cause of data loss. The _.debounce() function should avoid this issue by running the trailing debounce immediately if the tab is closed prior to the trailing timeout. This should only happen while running inside a browser because it's not relevant in headless runtimes (e.g. Node.js).

jgonggrijp commented 1 year ago

Closing this for the same reason as #2984. Please take any discussion there.