From c974f4a82ee3cd4b5b73b95d66d99854a0e5d3bc Mon Sep 17 00:00:00 2001 From: Adriel Santiago Date: Wed, 23 Jan 2019 18:06:40 -0500 Subject: Handle window and container resize events Resizes metrics graph on window and sidebard width changes --- app/assets/javascripts/lib/utils/common_utils.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/assets/javascripts/lib/utils/common_utils.js') 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 @@ -220,6 +220,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` -- cgit v1.2.3