Created
June 13, 2019 17:15
-
-
Save vovimayhem/14e1368afb956663bf32243ee39d4946 to your computer and use it in GitHub Desktop.
ember-infinity and jsonapi pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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