There’s often time where you want to observe width/height of an element in an easy way. There’s been many trick but with the new ResizeObserver
API, it’s easier than ever. Though not every browser supports this API, so there should still be a fallback to dirty checking/other method if needed.
Here is an example of what a simple implementation for size observation custom attribute would be:
https://gist.dumber.app/?gist=a51a80be7dc589c6ad8feeae6853afda&open=src%2Fsize-observer.js
The usage of such attribute would be:
<div size.bind="size"></div>
Now whenever size of the div element above changes, our size
property will be updated with the new width/height accordingly.