DockYard / ember-in-viewport

Detect if an Ember View or Component is in the viewport @ 60FPS
MIT License
245 stars 91 forks source link

Lazy load rAf implementation #251

Open mehulkar opened 4 years ago

mehulkar commented 4 years ago

It would be nice if the rAF implementation was not loaded if the browser supports IntersectionObserver.

snewcomer commented 4 years ago

Hey! Could you detail what you are thinking in this regards? I looked around and tried digging up some ideas - we don't initialize the raf-pool if the browser supports IObserver (thus no requestAnimationFrame). I'm sure I missed something though.

mehulkar commented 4 years ago

I was thinking this whole file: https://github.com/DockYard/ember-in-viewport/blob/master/addon/-private/raf-admin.js and the raf-pool dependency could be changed to be dynamically imported, and only loaded if IntersectionObserver is not defined. Not quite sure how/when that would happen.

snewcomer commented 4 years ago

That seems like an optimal idea! Although I think we would need to make the async chain all the way up to watchElement...Certainly worth exploring but would be quite a big change.