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

Enabling intersection observer options. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheodorTomas
Copy link

Passing down intersection observer options via the args object.

@tazsingh
Copy link
Member

tazsingh commented Nov 1, 2018 via email

@TheodorTomas
Copy link
Author

TheodorTomas commented Nov 1, 2018 via email

@tazsingh
Copy link
Member

tazsingh commented Nov 1, 2018 via email

@TheodorTomas
Copy link
Author

TheodorTomas commented Nov 2, 2018 via email

@tazsingh
Copy link
Member

tazsingh commented Dec 6, 2018

Hey sorry for the delay. I'm just getting back from vacation. Will be able to take a deeper look at this and the other issues on Monday. Will check back in then.

mount(<Loader {...props} />)

expect(mock).toHaveBeenCalledWith(expect.anything(), opts.observerOptions)
global.IntersectionObserver = IntersectionObserver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this and setting up the mock should be done in a beforeEach and afterEach for this test (perhaps wrap it in a describe), such that the mock is ensured to be cleaned up in the case that this test exits prematurely.

@tazsingh
Copy link
Member

@TheodorTomas Sorry again for taking so long. Back at the computer now.

Taking a fresh look at this PR, I am unsure of the proposed implementation only because the IntersectionObserver is set up once globally. However, the observerOptions can be passed into each call to react-loadable-visibility but only the 1st mounted loadable will actually set up the IntersectionObserver.

Instead I'd like to propose a different approach that I'd like to hear your thoughts on:

import { provideIntersectionObserverOptions } from 'react-loadable-visibility'

// This is called as many times as you like, but affects all the loadables.
// I think it's a bit more obvious in this case that it's a global call and
// we can continue with this implementation until someone needs a
// more fine-grained approach of a per-loadable IntersectionObserver
// with its own options.
provideIntersectionObserverOptions({
  whatever: 'option'
})

What do you think?

@jasonbiondo
Copy link

@tazsingh is there a better solution for this now? It seems like this never got merged and I would like to be able to setup a threshold for when to have the observer kick on.

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

Successfully merging this pull request may close these issues.

3 participants