mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-13 16:14:27 +02:00
Create simple debounce and throttle instead of _.
This commit is contained in:
parent
ae0030daa7
commit
e6d7edd130
7 changed files with 43 additions and 8 deletions
17
src/js/util/debounce.js
Normal file
17
src/js/util/debounce.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = function(func, time, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
var later = function() {
|
||||
timeout = null;
|
||||
if (!immediate) {
|
||||
func.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, time);
|
||||
if (callNow) {
|
||||
func.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
};
|
13
src/js/util/throttle.js
Normal file
13
src/js/util/throttle.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = function(func, time) {
|
||||
var wait = false;
|
||||
return function() {
|
||||
if (!wait) {
|
||||
func.apply(this, arguments);
|
||||
wait = true;
|
||||
|
||||
setTimeout(function() {
|
||||
wait = false;
|
||||
}, time);
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue