{"size": 1432, "ext": "js", "max_stars_repo_path": "node_modules/phaser3-rex-plugins/plugins/firebase/firestore/pageloader/LoadCurrentPage.js", "max_stars_repo_name": "SamueleDelMoro/ACTAM.Project2122-TraningGame", "max_stars_repo_stars_event_min_datetime": "2018-03-29T05:11:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:02:58.000Z", "max_issues_repo_path": "node_modules/phaser3-rex-plugins/plugins/firebase/firestore/pageloader/LoadCurrentPage.js", "max_issues_repo_name": "SamueleDelMoro/ACTAM.Project2122-TraningGame", "max_issues_repo_issues_event_min_datetime": "2018-07-20T07:39:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:08:01.000Z", "max_forks_repo_path": "node_modules/phaser3-rex-plugins/plugins/firebase/firestore/pageloader/LoadCurrentPage.js", "max_forks_repo_name": "SamueleDelMoro/ACTAM.Project2122-TraningGame", "max_forks_repo_forks_event_min_datetime": "2018-05-17T06:45:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T11:48:52.000Z"}
{"max_stars_count": 888, "max_issues_count": 194, "max_forks_count": 262, "avg_line_length": 35.8, "max_line_length": 93, "alphanum_fraction": 0.6180167598}
import Load from '../utils/query/Load.js';

var LoadCurrentPage = function () {
    if ((this.pageIndex === undefined) || (this.pageIndex === 0)) {
        return this.loadFirstPage();
    }

    var callback = (this.dataMode === 0) ? LoadStaticPage : LoadDynamicPage;
    return callback.call(this);
}

var LoadStaticPage = function () {
    var self = this;
    return Load(this.nextQuery, this.itemCount, 0, this.prevPageEndDocRef, 'startAfter')
        .then(function (docs) {
            var docCount = docs.length;
            self.cacheItems = docs;
            self.endItemIndex = self.startItemIndex + docCount - 1;
            self.isFullPage = (docCount === self.itemCount);
            // Doc reference for paging
            self.currPageStartDocRef = docs[0];
            self.currPageEndDocRef = docs[docCount - 1];
            return Promise.resolve(self.cacheItems);
        })
}

var LoadDynamicPage = function () {
    var skip = this.pageIndex * this.itemCount;
    var self = this;
    return Load(this.nextQuery, this.itemCount, skip, this.baselineDocRef, this.baselineMode)
        .then(function (docs) {
            var docCount = docs.length;
            self.cacheItems = docs;
            self.endItemIndex = self.startItemIndex + docCount - 1;
            self.isFullPage = (docCount === self.itemCount);
            return Promise.resolve(self.cacheItems);
        })
}

export default LoadCurrentPage;