private runQuery()

in packages/tablesorter/src/TableSorter.ts [408:451]


    private runQuery(newQuery: boolean) {
        // If there is already a thing goin, stop it
        if (newQuery && this.loadingPromise) {
            this.loadingPromise["cancel"] = true;
        }

        if (!this.dataProvider) {
            return;
        }

        // Let everyone know we are loading more data
        this.raiseLoadMoreData();

        // We should only attempt to load more data, if we don't already have data loaded, or there is more to be loaded
        return this.dataProvider.canQuery(this.queryOptions).then((value) => {
            if (value) {
                this.loadingData = true;
                const promise = this.loadingPromise = this.dataProvider.query(this.queryOptions).then(r => {

                    // if this promise hasn't been cancelled
                    if ((!promise || !promise["cancel"]) && !this.destroyed) {
                        this.loadingPromise = undefined;
                        this.loadDataFromQueryResult(r);

                        this.loadingData = false;

                        // make sure we don't need to load more after this, in case it doesn't all fit on the screen
                        setTimeout(() => {
                            this.checkLoadMoreData(false);
                            if (!this.loadingPromise) {
                                this.loadingData = false;
                            }
                        }, 10);
                    }
                }, () => this.loadingData = false)
                .then(undefined, (err) => {
                    throw err;
                });
                return promise;
            } else {
                this.loadingData = false;
            }
        });
    }