This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): debounce resize callback
- The resize event fires often, so debouncing the function execution can improve performance dramatically
- Loading branch information
Showing
2 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Debounces functions | ||
* | ||
* Taken from UI Bootstrap $$debounce source code | ||
* See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js | ||
* | ||
*/ | ||
uis.factory('$$uisDebounce', ['$timeout', function($timeout) { | ||
return function(callback, debounceTime) { | ||
var timeoutPromise; | ||
|
||
return function() { | ||
var self = this; | ||
var args = Array.prototype.slice.call(arguments); | ||
if (timeoutPromise) { | ||
$timeout.cancel(timeoutPromise); | ||
} | ||
|
||
timeoutPromise = $timeout(function() { | ||
callback.apply(self, args); | ||
}, debounceTime); | ||
}; | ||
}; | ||
}]); |