-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResizeObserver + polyfill as alternative to element-resize-detector #156
Comments
Sounds like a great idea. I came across this addon when looking for a ResizeObserver-based modifier -- that was my expectation of how this problem would likely be solved. |
I'd like to see how well a modifier based on My application is for |
So I looked into this a bit and found out a couple of things while tinkering with a ResizeObserver proof of concept for this addon:
Thoughts are welcome! |
I built ember-resize-observer-service to solve exactly the problem with multiple Building a size-responsive modifier with it is pretty straight forward: export default class OnResizeModifier extends Modifier {
@service resizeObserver;
didInstall() {
this.resizeObserver.observe(this.element, this.handleResize);
}
willRemove() {
this.resizeObserver.unobserve(this.element, this.handleResize);
}
@action
handleResize(...args) {
let [callback] = this.args.positional;
callback(...args);
}
} @nickschot If you need a complete ResizeObserver based solution with a single instance optimization, I built ember-on-resize-modifier. And in case if you need a polyfill:
|
If it already exists it makes sense to migrate to that addon in my opinion. As far is I can see (after a very quick peek) the main feature difference is that your addon also runs on insert. For my use cases that doesn’t matter though. |
I've noticed the element-resize-detector is quite a huge library for what it does. Were using the native ResizeObserver + a polyfill like https://www.npmjs.com/package/resize-observer-polyfill (2.44kB gzipped) considered? Seems like it would work just as well and save many KB. The polyfill could even be loaded conditionally based on ember's
config/targets.js
feature.The text was updated successfully, but these errors were encountered: