Implementation of a 'reload' method (extremely useful to rebind an updated DOM) #153

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@antoinekociuba
Contributor

Sometimes, DOM can be updated by external actions/scripts (especially the items container).

It results that the infinite scroll is not working anymore, due to an obsolete binded DOM in getLastItem() method. It results the following incorrect calculation in getScrollThreshold() method:

$lastElement.offset().top will always equal 0.
$lastElement.height() will always equal 0.
currentScrollOffset >= scrollThreshold will never happen in scrollHandler() method.

By using the new reload() method after a DOM change, we redefine items container and calculations are back to normal.

@antoinekociuba antoinekociuba Implementation of the 'reload' method (extremely useful to rebind an …
…updated DOM)
3bc3ed6
@fieg
Member
fieg commented Jul 24, 2014

Thank you for your work, it looks absolutely good, although I was brainstorming about one thing (not sure if it would work): perhaps we can achieve the same functionality with less code if the redefining of the this.$itemsContainer would happen in the bind method? This way someone could simply call unbind and bind to reload and we could even make a simple convenience method like this:

reload = function() {
  this.unbind();
  this.bind();
}

Please let me know how you think about this and if you think this would work.

@antoinekociuba
Contributor

Hi Jeroen,

Actually, redefining this.$itemsContainer in bind method is a really good idea and we avoid code duplication. So I'd go for that solution. :)

But in that case, I don't see any interest of using a reload method as we can call direcly unbind and bind as we need, depending on the purpose.

(Thank you for that plugin btw :))

@fieg fieg referenced this pull request Oct 14, 2014
Closed

Caching items container #161

@fieg fieg closed this in 3ae5b4e Dec 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment