-
-
Notifications
You must be signed in to change notification settings - Fork 43
Use a single ResizeObserver instance #26
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
Conversation
|
I don't think attaching extra props to native objects like an HTMLElement is a good idea. |
|
Keeping track of observed elements seems a bit redundant, as ResizeObserver already does just that? |
|
Just doesn't feel right to mutate native objects. |
|
What do you think about dispatching a custom event on the element and adding a listener for it in the hook? |
|
Honestly I'm just not convinced this would worth doing at this point, regardless of the solution. Anyway, here are some thoughts:
All in all at the current state I think it's not worth the effort. Maybe if someone made performance benchmarks where it's clear that this would become a real-life bottleneck I'd consider it, but at the moment it feels like way too much work for way too little. |
|
I thought I solved this for a second. I could add a However within the callback the hooks add, it needs to find the entry that's relevant for the given hook, based on the element observed. This can be done by using a for loop over the entries array, until target === observed element. This means that as more hooks (and therefore more observed elements) are added, the entries array might grow in size as well. ☝ This might be something worth looking into though, might not be such a big issue. Only if a LOT of elements change within the same tick, which would mean that all of these hook-added callbacks would need to loop through the entries array to find only the relevant entry for themselves. Again, these are the sort of things that really need benchmarking. 😅 |
|
See #24 |
No description provided.