Commit 7c88890f authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate observe-element-size module to TS

parent 6df3b42d
...@@ -7,13 +7,14 @@ import { ListenerCollection } from '../../shared/listener-collection'; ...@@ -7,13 +7,14 @@ import { ListenerCollection } from '../../shared/listener-collection';
* Returns a cleanup function which should be called to remove observers when * Returns a cleanup function which should be called to remove observers when
* updates are no longer needed. * updates are no longer needed.
* *
* @param {Element} element - HTML element to watch * @param element - HTML element to watch
* @param {(width: number, height: number) => void} onSizeChanged - * @param onSizeChanged - Callback to invoke with the `clientWidth` and
* Callback to invoke with the `clientWidth` and `clientHeight` of the * `clientHeight` of the element when a change in its size is detected.
* element when a change in its size is detected.
* @return {() => void}
*/ */
export function observeElementSize(element, onSizeChanged) { export function observeElementSize(
element: Element,
onSizeChanged: (width: number, height: number) => void
): () => void {
if (typeof ResizeObserver !== 'undefined') { if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(() => const observer = new ResizeObserver(() =>
onSizeChanged(element.clientWidth, element.clientHeight) onSizeChanged(element.clientWidth, element.clientHeight)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment