Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Infinite mode getNextPage resets the collection #315

Open
ristovskiv opened this issue Mar 7, 2016 · 3 comments
Open

Infinite mode getNextPage resets the collection #315

ristovskiv opened this issue Mar 7, 2016 · 3 comments

Comments

@ristovskiv
Copy link

In infinite mode on collection.getNextPage instead of models being add to the collection, the collection resets with the models from the current page.

Here is my collection code.

class LoopCampaigns.Collections.MailTemplates extends Backbone.PageableCollection

  url: "/api/mail_templates"

  mode: 'infinite'

  state:
   pageSize: 10

  model: LoopCampaigns.Models.MailTemplate

  parseRecords: (response)->
    return response['mail_templates']

  parseLinks: (response)->
    return {next: response.links.next, first: response.links.first, prev: response.links.prev, total_entries: response.links.total_entries}

here is a preview from the json response from my Rails API

{
"mail_templates": [
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...}
],
"links": {
"first": "/api/mail_templates?page=1",
"next": "/api/mail_templates?page=2",
"prev": "/api/mail_templates?page=0",
"total_entries": 16
}
}
@emileber
Copy link

In infinite mode, there's a fullCollection inside your collection which serves as a container for the already fetched models, but only the current page is in the collection models array.

If you're after infinite scroll or something akin to this, without a need for paging, I made an infinite collection inspired by the API of this lib.

@turkus
Copy link

turkus commented Feb 17, 2017

@wyuenho I experienced the same issue. Any other clues?

@emileber
Copy link

@turkus Backbone.paginator is not meant to be used this way and the pagination behavior is too deeply ingrained in the collection to work around it. You'd better be implementing your own collection. See issue #344

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

No branches or pull requests

3 participants