Open tilwinjoy opened 6 years ago
I think lib will expect to have actual models aswell, so beside having links for all pages, you probably need to generate (and then update) some stub models. I believe that lib just slice models from fullCollection
, without actually fetching it.
Links persistent checked few lines above
I face the problem that i want reuse already fetched models, and having a paging, that means that i need to load pages from first to last sequentially, to prevent fullCollection
break.
As a temporarily "fix" i have override getPage
method to switch to server mode for initial fetch, but it will break, if next page would be >1 from the current (no link for it in state)
import PageableCollection from 'backbone.paginator';
export class Foo extends PageableCollection {
getPage(index, options) {
const useServerMode = (
index > this.state.firstPage &&
this.length === 0 &&
this.mode === 'infinite'
);
if (useServerMode) {
const fetch = false; // Prevent unnecessary fetch while switching modes
this.switchMode('server', {
fetch
});
this.once('sync', function() {
this.switchMode('infinite', {
fetch
});
}, this);
}
return super.getPage(index, options)
}
}
@ogonkov I've invited you as a collaborator of this repo. Since I don't use this library much anymore, it'd be nicer for someone who knows what's going on to help maintain it.
@wyuenho thank you
I have an API that returns the number of records, but not the "next", "previous" headers/response data. I want to fetch info from this API using infinite scroll.
Currently if I try to use "server" mode with total records every request will clear previous models. If I try to use "infinite" mode I need to generate the links myself.
It'd be cool if the plugin requests next page as in "server" mode when "total_records" is available instead of looking for links in "infinite" mode.