diff options
author | Adriel Santiago <adriel@gitlab.com> | 2019-01-24 02:06:40 +0300 |
---|---|---|
committer | Adriel Santiago <adriel@gitlab.com> | 2019-02-04 16:04:45 +0300 |
commit | c974f4a82ee3cd4b5b73b95d66d99854a0e5d3bc (patch) | |
tree | 183122acce41af316c31515c5c7431e886db282b /app/assets/javascripts/lib/utils/common_utils.js | |
parent | 2b0f4df0217b4a4aee53f964610d66ceedb68dca (diff) |
Handle window and container resize events
Resizes metrics graph on window and sidebard width changes
Diffstat (limited to 'app/assets/javascripts/lib/utils/common_utils.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index ae8b4b4d635..0ceff10a02a 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -221,6 +221,22 @@ export const scrollToElement = element => { }; /** + * Returns a function that can only be invoked once between + * each browser screen repaint. + * @param {Function} fn + */ +export const debounceByAnimationFrame = fn => { + let requestId; + + return function debounced(...args) { + if (requestId) { + window.cancelAnimationFrame(requestId); + } + requestId = window.requestAnimationFrame(() => fn.apply(this, args)); + }; +}; + +/** this will take in the `name` of the param you want to parse in the url if the name does not exist this function will return `null` otherwise it will return the value of the param key provided |