QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.76k stars 1.3k forks source link

[✨] Remove Event Listener after event is invoked once #3464

Open theonlychase opened 1 year ago

theonlychase commented 1 year ago

Is your feature request related to a problem?

The problem I am having is not being able to remove an event listener after it is invoked once, either by setting it on the element itself, or by creating an event using the useOn hook.

Describe the solution you'd like

The ability to set any of the event listener options, such as { once: true }. The event listener would automatically be removed after being invoked once.

Describe alternatives you've considered

As an example, I am currently using state to handle a window onScroll event that I only want triggered once based on the scroll position.

Additional context

Another option is using an intersection observer. I understand there is useVisibleTask?(), which can use an observer under the hood, but there is no way to set any of the Intersection Observer Options, or see the properties on the entry itself, such as the intersectionRatio. If the component/element is above the fold on page load, that Javascript gets loaded right away, which I want to avoid.

PatrickJS commented 5 months ago

you can add an attribute to the element and check the value

gioboa commented 6 days ago

@theonlychase is it solved?

github-actions[bot] commented 6 days ago

Hello @theonlychase. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏