DockYard / ember-in-viewport

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

onExit doesn't fire unless viewportSpy is enabled #275

Open XuluWarrior opened 3 years ago

XuluWarrior commented 3 years ago

270 added the viewportSpy option which means that if it is disabled, after onEnter, stopWatching is called.

This makes sense if you're only considering onEnter but if onExit is defined, then it is counterintuitive that it never gets called unless viewportSpy is set to true.

It took me a while to realise why {{in-viewport onEnter=this.onEnter onExit=this.onExit}} only called my onEnter handler.

I would propose a change to the check on https://github.com/DockYard/ember-in-viewport/blob/e052a89b7a0322d21aec69b9e6e3f7c08bf5bfd2/addon/modifiers/in-viewport.js#L45 to

if (!this.options.viewportSpy && !this.args.named.onExit) {