DockYard / ember-in-viewport

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

Pass more data back to callbacks #227

Open mehulkar opened 4 years ago

mehulkar commented 4 years ago

The onEnter and onExit callbacks currently receive the watched element as the first argument. It would be useful to receive the options that were passed when registering the callback as well.

My use case is currently only for testing. I want to test that the correct value is passed for the scrollableArea option. It's a bit hard to write a test that actually asserts the behavior of IntersectionObserver and its implementation of the root argument. Since my abstraction for IO is this addon, I could write my test case to the API provided here instead.

Something like this:

<div {{in-viewport onEnter=this.foo scrollableArea=".something"}}>

{{!-- 
function foo(element, options) {
  assert.equal(options.scrollableArea, '.something');
}
--}}

I think this could be achieved by binding these options before adding them to rafAdmin or observerAdmin when adding the callbacks.