Merge pull request #219 from nauzilus/downloader-fix Debounce multiple rapid generateCode calls.
diff --git a/download.js b/download.js
index c1006da..f7de2f4 100644
--- a/download.js
+++ b/download.js
@@ -241,9 +241,17 @@ function update(updatedCategory, updatedId){
title: prettySize(total.css)
});
- generateCode();
+ delayedGenerateCode();
}
+var timerId = 0;
+// "debounce" multiple rapid requests to generate and highlight code
+function delayedGenerateCode(){
+ if ( timerId !== 0 ) {
+ clearTimeout(timerId);
+ }
+ timerId = setTimeout(generateCode, 500);
+}
function generateCode(){
var code = {js: '', css: ''};