Skip to content

Instantly share code, notes, and snippets.

@vovimayhem
Created June 13, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vovimayhem/14e1368afb956663bf32243ee39d4946 to your computer and use it in GitHub Desktop.
Save vovimayhem/14e1368afb956663bf32243ee39d4946 to your computer and use it in GitHub Desktop.
ember-infinity and jsonapi pagination
import { resolve } from 'rsvp';
import { merge } from '@ember/polyfills';
import { isPresent } from '@ember/utils';
import InfinityModel from 'ember-infinity/lib/infinity-model';
export default InfinityModel.extend({
canLoadMore: true,
buildParams(increment) {
let pageParams = {};
const offset = (this.currentPage + increment) -1;
if (offset > 0) pageParams['offset'] = offset;
merge(this.extraParams['page'], pageParams);
return this.extraParams;
},
async afterInfinityModel(collection) {
const { links: { next: nextPageLink } } = collection;
this.set('canLoadMore', isPresent(nextPageLink));
return resolve(collection);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment