Created
May 8, 2019 12:24
-
-
Save GavinJoyce/079b1f9f6486edfcf4a05774adbafca0 to your computer and use it in GitHub Desktop.
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
import functionalModifier from "ember-functional-modifiers"; | |
import ResizeObserver from "resize-observer-polyfill"; | |
export function onResize(element, [action]) { | |
let resizeObserver = new ResizeObserver(entries => { | |
let entry = entries[0]; | |
if (entry) { | |
let rectangle = entry.contentRect; | |
let data = { | |
left: rectangle.left, | |
right: rectangle.right, | |
top: rectangle.top, | |
bottom: rectangle.bottom, | |
width: rectangle.width, | |
height: rectangle.height, | |
x: rectangle.x, | |
y: rectangle.y, | |
}; | |
action(data); | |
} | |
}); | |
resizeObserver.observe(element); | |
return () => { | |
resizeObserver.unobserve(element); | |
}; | |
} | |
export default functionalModifier(onResize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment