From ccb14e472f0b40cffd3ee6bda87a38ab42ae8554 Mon Sep 17 00:00:00 2001
From: Ardis Lu line-clamp.
It's helpful to debounce ResizeObserver's event listener for better performance. Using this basic debounce function:
+function debounce(fn, wait) {
+ let timeoutId;
+ return () => {
+ clearTimeout(timeoutId);
+ timeoutId = setTimeout(fn, wait);
+ }
+}
+ You can update the event listener to cancel if another event is fired within 200 milliseconds:
+
+new ResizeObserver(debounce(() => elem.style.setProperty('--lines', Math.floor(elem.clientHeight / getLineHeightInPx(elem))), 200)).observe(elem);