Closed tj closed 10 years ago
+1 on infinite scrolling
Do we already have a component for that? Haha :D
I haven't noticed one, but we should definitely make one rather than just in-lining in this project.
Hm, how should we design the API? One function à la scroll([frame], parent, content)
?
Where content
is a function that returns DOMElement
s that then get appended to parent
.frame
is optional and defaults to parent
and is the DOMElement
we listen on for scroll events.
infinite(el, loadCallback)
should be good enough to get started but it would need flexibility to prime the page etc as well
I'm utterly sorry, but what exactly do you mean by "priming the page"?
How can this component be flexible? It's only purpose is to load elements from loadCallback
and append them to el
. Haha.
It should also detect when we get to the bottom of el
. Perhaps it would also make sense to have it take responsibility for requesting the first set of elements from loadCallback
as well (might be simpler than pre-filling them into the page)
infinite would start hitting on loadCallback
everytime the user gets near the end. This way we're not bombing the server, but have no visual lag for the user.
What about loadCallback
returning an array of 10 to 20 elements?
it doesn't need to do much other than detect the scrolling threshold, insertion of the elements could be up to the user
Here it is: infinite(el, loadCallback, [margin])
If you're ok with this I'll try to implement it in the search.
sweet :D probably worth debouncing the onscroll to ~100ms or so but sounds good!
@silvinci nice stuff !
@Nami-Doc Thanks. :)
@visionmedia After one load is triggered, all following scroll events are ignored, until loadCallback
makes Infinite
resume.
infinite(el, function(iteration, resume) {
resume();
}):
But I can switch to debounce
, if you want to. But this might issue some unnecessary calls, as some ajax request might take up longer than 100ms.
ah I see, maybe add a counter like ++this.page
when it goes to load, then you can compare the offset expected to trigger the next "page" regardless of it being ready or not
Uhm, isn't that what iteration
is for? Haha. It goes 1 up, everytime loadCallback
is issued.
So shall I just remove that resume()
callback and then debounce? You'd still be able to Infinite.pause()
and Infinite.resume()
.
ah missed that
I think debouncing is safe, as all that could possibly happen, is that we load up a bit of data, that isn't used right now, but would be loaded at the next scroll event anyways.
Okay, it now debounces 100ms. I'll try to implement it.
limited to 25 components now. shit was super slow before, especially when using reactive
not a big deal right now but once we have more components the initial dom junk will be pretty heavy if we dont do an infinite scrolling sort of display