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

Could observe one element only once #119

Closed
thearnica opened this issue Sep 13, 2018 · 6 comments
Closed

Could observe one element only once #119

thearnica opened this issue Sep 13, 2018 · 6 comments

Comments

@thearnica
Copy link

Simple problem - as long you are tracking elements via INSTANCE_MAP.set(element, instance) - one element could be associated with one one instance.

If, but any reason, 2 different observers observe one element - only one would work - the top one.

@thebuilder
Copy link
Owner

Do you have an example of how that could be achieved? You'd have to give the same ref to two different observers?

@thearnica
Copy link
Author

Yep. In my case I have 2 "levels" of Observers, let call it "block level" and "element level", to produce something like "waterfall" animation - "internal" observer should not fire until "parent" block will "enough" visible.
But sometimes, due to BEM for example, top level block and inner element is the same DOM element.
Result - it keeping be invisible.

@thebuilder
Copy link
Owner

This seems like an edge case, that is related to the DOM structure of your component. I'm guessing you could solve it by ensuring you don't use the same element for both observers?

It would require a complete rewrite of the Intersection handler in react-intersection-observer to support this, since it's built around the concept of an element having a single observer instance.

@thearnica
Copy link
Author

If you could not support it yet - what about printing some debug information when someone starts observing already observed node?
To be honest - it was quite hard to understand why some parts of my application does not works, while everything else works well :)

@thebuilder
Copy link
Owner

thebuilder commented Sep 13, 2018

That's fair. I'll add an invariant log message if the element is already used. 👍

@thebuilder
Copy link
Owner

I just published a version that throws an error if you try to observe the same element twice. Give it a try!

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

2 participants