Last active
August 17, 2022 10:11
-
-
Save marc-hughes/8302149 to your computer and use it in GitHub Desktop.
debounce function for dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void saveWord(Word word) { ... } | |
... | |
debounce(800, saveWord, [word]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man