Idea: Debounce and throttle options for observing traits
See original GitHub issueTwo use cases:
- Using interact or a slider that causes something to execute which say takes ~100 ms to complete, you don’t want events to be delivered all the time, but you may want to update it say every 250 ms, when a slider is changing value.
- I’m using bqplot and listening to a change in the min value of one of the axes. Only when it didn’t change for say 500msec, I expect the user to be done with zooming and panning and will start a heavy computation to rebuild the figure.
If this is done on the client side (js), this will also lead to less traffic/events.
I can imaging something like this
interact(f, x=10, throttle=250);
For the bqplot use case
scale_x.observe(f, "xmin", debounce=500)
See here for a visual explaination: http://benalman.com/projects/jquery-throttle-debounce-plugin/
throttle and debounced functions are also available in underscore
Having them in link and js(d)link could also be useful (say when a widget would make a ajax request)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:20 (9 by maintainers)
Top Results From Across the Web
How to Debounce and Throttle Callbacks in Vue
1. Debouncing a watcher ... Open the demo. Open the demo and type a few characters into the input. Each time you type,...
Read more >Debouncing and Throttling Explained Through Examples
Debounce and throttle are two similar (but different!) techniques to control how many times we allow a function to be executed over time....
Read more >Debounce and Throttle in Real Life Scenarios | by Kfir Zuberi
Debounce and throttle are recommended to use on events that fire more often than you need them to. You may have come across...
Read more >Add event throttling and debouncing to ...
The change event fires multiple times in rapid succession, e.g., when the user's connection switches from Wi-Fi to cellular 2, so it would...
Read more >How To Implement Debounce And Throttle In JavaScript
The reason throttle is ideal for these scenarios is that every time the delay ends you will get updated information on the event...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
(This workaround aside, I still support the incorporation of throttling directly into the interact functionality, I guess it’s a few lines of code)
OK, for anyone who is interested, I found a workaround!
The solution is to code the interactivity yourself, having the sliders / controls use a throttled plot update function. The key trick to solve the flashing was to use
wait=True
when clearing the output widget. Here is a minimal code segment:This now no longer builds up an infinite queue of matplotlib updates! The refresh is not “instant” / video rate, but that is fine since for me it is more important that there is a visual indication of the interactivity as the slider is moved, and that when it stops moving, it goes quickly to the correct parameter. And this work at least 😃