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

Add support for turbolinks; Allow periodic checks while scrolling #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

cesmoak
Copy link

@cesmoak cesmoak commented Jun 30, 2015

For turbolinks, this does two main things:

  • element references are recached after next-page results are loaded
  • any requests initiated before a turbolinks pageload are ignored if they complete after the results are loaded.

For periodic checks while scrolling: the previous implementation would wait until scrolling stopped to check and potentially load the next page results. This change allows for checks to occur (periodically, at the scrollDelay frequency) so that results can be loaded while scrolling is still happening.

This change does two main things:
- element references are recached after next-page results are loaded
- any requests initiated before a turbolinks pageload are ignored if
they complete after the results are loaded

The element reference to the container element is made by attaching a
unique data attribute to it: “data-jquery-infinite-pages-container” and
setting the value to a unique id for the instance of InfinitePages.

Requests are ignored by keeping a queue of timestamps marking when they
begin and keeping a timestamp of the last time turbolinks changed the
page, invalidating all before that last page-load.
The previous implementation would wait until scrolling stopped to check
and potentially load the next page results. This change allows for
checks to occur (periodically, at the scrollDelay frequency) so that
results can be loaded while scrolling is still happening.
We need to actually call shouldCheck.
scrollTimeout = setTimeout(scrollHandler, 250)
scrollTimeout = setTimeout(scrollHandler, scrollDelay)

# Set a data attribute so we can find again after a turbolink page is loaded

Choose a reason for hiding this comment

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

Line exceeds maximum allowed length

In the previous version, the old $container element could still be
referenced once a page load occurred. This fixes that problem by
passing the old $container element reference to the post-load methods,
ensuring a newer reference to the container is not incorrectly updated.
# Debounce scroll event to improve performance
scrollTimeout = null
scrollHandler = (=> @check())
# Set a data attribute so we can find again after a turbolink page is loaded

Choose a reason for hiding this comment

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

Line exceeds maximum allowed length

@mbajur
Copy link

mbajur commented Feb 9, 2016

👍

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