Skip to content
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

inView lifecycle method #6443

Closed
aantusahaa opened this issue Jun 25, 2021 · 4 comments
Closed

inView lifecycle method #6443

aantusahaa opened this issue Jun 25, 2021 · 4 comments

Comments

@aantusahaa
Copy link

Is your feature request related to a problem? Please describe.
Not really a problem. Rather a convenience thing.

Describe the solution you'd like
A method namely inView() that will run whenever the component came into the viewport. It could use IntersectionObserver behind the scene.

Describe alternatives you've considered
Currently, I can use an component around the component I want to listen to.

How important is this feature to you?
For me, it will be a welcoming feature. Whatever projects I do more often than not it involves some use of IntersectionObserver.

@bluwy
Copy link
Member

bluwy commented Jun 27, 2021

How actually do we detect that a component comes into the viewport? IntersectionObserver relies on observing a DOM element. Since a component can have multiple root elements, should we trigger the inView lifecycle when at least one element enters the view, or only when all of them enters?

There seems to be a lot of unknowns here, which I think should be handled off to a library or a custom action, like svelte-inview.

@aantusahaa
Copy link
Author

aantusahaa commented Jun 27, 2021

Since a component can have multiple root elements, should we trigger the inView lifecycle when at least one element enters the view, or only when all of them enters?

We could define that in some sort of config object or even in the DOM elements itself.

I wasn't aware of svelte-inview . Thanks for that.

@bluwy
Copy link
Member

bluwy commented Jun 27, 2021

We could define that if some sort of config object or even in the DOM elements itself.

Sounds like a perfect use case for a Svelte action :) Personally I find the API from svelte-inview much easier to work with, than having an inView lifecycle function. If anything, Svelte could instead provide these actions by default, which tracked at sveltejs/rfcs#24

@tanhauhau
Copy link
Member

you can implement your own action, and there's no plan of having any built-in actions within Svelte right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants