Created
August 18, 2020 12:53
-
-
Save YoranBrondsema/2333b1d7cab6d1393523d94d001499c4 to your computer and use it in GitHub Desktop.
on-element-resize modifier for Ember.js
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 { modifier } from 'ember-modifier'; | |
import { run } from '@ember/runloop'; | |
export default modifier(function onElementResize(element, [fn]) { | |
const observer = new window.ResizeObserver(() => { | |
run(() => { | |
fn(element); | |
}); | |
}); | |
observer.observe(element); | |
return () => { | |
observer.disconnect(); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment