@tanstack/query-core
Version:
The framework agnostic core that powers TanStack Query
71 lines (70 loc) • 2.16 kB
JavaScript
import "./chunk-WPSKCR32.js";
// src/infiniteQueryObserver.ts
import { QueryObserver } from "./queryObserver.js";
import {
hasNextPage,
hasPreviousPage,
infiniteQueryBehavior
} from "./infiniteQueryBehavior.js";
var InfiniteQueryObserver = class extends QueryObserver {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(client, options) {
super(client, options);
}
bindMethods() {
super.bindMethods();
this.fetchNextPage = this.fetchNextPage.bind(this);
this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
}
setOptions(options, notifyOptions) {
super.setOptions(
{
...options,
behavior: infiniteQueryBehavior()
},
notifyOptions
);
}
getOptimisticResult(options) {
options.behavior = infiniteQueryBehavior();
return super.getOptimisticResult(options);
}
fetchNextPage(options) {
return this.fetch({
...options,
meta: {
fetchMore: { direction: "forward" }
}
});
}
fetchPreviousPage(options) {
return this.fetch({
...options,
meta: {
fetchMore: { direction: "backward" }
}
});
}
createResult(query, options) {
var _a, _b, _c, _d;
const { state } = query;
const result = super.createResult(query, options);
const { isFetching, isRefetching } = result;
const isFetchingNextPage = isFetching && ((_b = (_a = state.fetchMeta) == null ? void 0 : _a.fetchMore) == null ? void 0 : _b.direction) === "forward";
const isFetchingPreviousPage = isFetching && ((_d = (_c = state.fetchMeta) == null ? void 0 : _c.fetchMore) == null ? void 0 : _d.direction) === "backward";
return {
...result,
fetchNextPage: this.fetchNextPage,
fetchPreviousPage: this.fetchPreviousPage,
hasNextPage: hasNextPage(options, state.data),
hasPreviousPage: hasPreviousPage(options, state.data),
isFetchingNextPage,
isFetchingPreviousPage,
isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
};
}
};
export {
InfiniteQueryObserver
};
//# sourceMappingURL=infiniteQueryObserver.js.map