Skip to content

Requesting more pages than necessary #171

@ghost

Description

I have an issue where more pages are requested than necessary. In this example, I only have 8 results returned from the API. my pageSize is set at 25 to fetch 25 results/page. However, it requested 6 pages worth of data, which all returned empty except the first. I'm not sure what I'm doing wrong.

screenshot 2017-04-07 18 01 55

template

  {{#impagination-dataset
     fetch=(route-action 'fetch')
     on-init=(action 'initializeReadOffset')
     on-object-at=(action "onObjectAt")
     page-size=pageSize
     as |transactions|}}
...

controller

import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';

const { Controller } = Ember;

export default Controller.extend({
  pageSize: 25,

  setReadOffset: task(function * (dataset, offset) {
    yield timeout(5);
    dataset.setReadOffset(offset);
  }).restartable(),

  actions: {
    initializeReadOffset(dataset) {
      this.get('setReadOffset').perform(dataset, 0);
    },

    onObjectAt(dataset, index) {
      this.get('setReadOffset').perform(dataset, index);
    }
  }
});

route

import Ember from 'ember';

export default Ember.Route.extend({
  model(params) {
    return this.store.findRecord('account', params.account_id);
  },

  actions: {
    fetch(pageOffset, pageSize, stats) {
      return this.store.query('transaction', {
        account_id: this.get('controller.model.id'),
        page: pageOffset + 1
      });
    }
  }
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions