Skip to content

Instantly share code, notes, and snippets.

@marc-hughes
Last active August 17, 2022 10:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marc-hughes/8302149 to your computer and use it in GitHub Desktop.
Save marc-hughes/8302149 to your computer and use it in GitHub Desktop.
debounce function for dart
library debounce;
Map timeouts = {};
void debounce(int timeoutMS, Function target, List arguments) {
if(timeouts.containsKey(target)) {
timeouts[target].cancel();
}
Timer timer = new Timer(new Duration(milliseconds: timeoutMS), () {
Function.apply(target, arguments);
});
timeouts[target] = timer;
}
void saveWord(Word word) { ... }
...
debounce(800, saveWord, [word]);
@amirrezasalimi
Copy link

thanks man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment