mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Debounce autobake in the web app.
Added debounce with guidance from the underscore.js implementation:
e944e0275a/underscore.js (L880)
This commit is contained in:
parent
21c0fed833
commit
50784f2600
2 changed files with 29 additions and 0 deletions
|
@ -1185,6 +1185,33 @@ const Utils = {
|
||||||
"Latin1": CryptoJS.enc.Latin1,
|
"Latin1": CryptoJS.enc.Latin1,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A utility for "debouncing" functions.
|
||||||
|
* Debouncing is when you want to ensure events triggered by an event are rate-limited.
|
||||||
|
* @constant
|
||||||
|
*/
|
||||||
|
debounce(fn, delay) {
|
||||||
|
let timeout;
|
||||||
|
|
||||||
|
return function() {
|
||||||
|
/**
|
||||||
|
* later calls the debounced function with arguments.
|
||||||
|
* If the debounced function is called again, then the timeout
|
||||||
|
* which calls later is cancelled.
|
||||||
|
*/
|
||||||
|
let later = () => {
|
||||||
|
fn.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout = setTimeout(later, delay);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Utils;
|
export default Utils;
|
||||||
|
|
|
@ -36,6 +36,8 @@ var App = function(categories, operations, defaultFavourites, defaultOptions) {
|
||||||
this.ingId = 0;
|
this.ingId = 0;
|
||||||
|
|
||||||
window.chef = this.chef;
|
window.chef = this.chef;
|
||||||
|
|
||||||
|
this.autoBake = Utils.debounce(this.autoBake, 300);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue