UNPKG

vue-use-query

Version:

vue use query

75 lines (74 loc) 4.22 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { QueryObserver } from './queryObserver'; import { hasNextPage, hasPreviousPage, infiniteQueryBehavior, } from './infiniteQueryBehavior'; var InfiniteQueryObserver = /** @class */ (function (_super) { __extends(InfiniteQueryObserver, _super); // eslint-disable-next-line @typescript-eslint/no-useless-constructor function InfiniteQueryObserver(client, options) { return _super.call(this, client, options) || this; } InfiniteQueryObserver.prototype.bindMethods = function () { _super.prototype.bindMethods.call(this); this.fetchNextPage = this.fetchNextPage.bind(this); this.fetchPreviousPage = this.fetchPreviousPage.bind(this); }; InfiniteQueryObserver.prototype.setOptions = function (options) { _super.prototype.setOptions.call(this, __assign(__assign({}, options), { behavior: infiniteQueryBehavior() })); }; InfiniteQueryObserver.prototype.getOptimisticResult = function (options) { options.behavior = infiniteQueryBehavior(); return _super.prototype.getOptimisticResult.call(this, options); }; InfiniteQueryObserver.prototype.fetchNextPage = function (options) { return this.fetch({ cancelRefetch: true, throwOnError: options === null || options === void 0 ? void 0 : options.throwOnError, meta: { fetchMore: { direction: 'forward', pageParam: options === null || options === void 0 ? void 0 : options.pageParam }, }, }); }; InfiniteQueryObserver.prototype.fetchPreviousPage = function (options) { return this.fetch({ cancelRefetch: true, throwOnError: options === null || options === void 0 ? void 0 : options.throwOnError, meta: { fetchMore: { direction: 'backward', pageParam: options === null || options === void 0 ? void 0 : options.pageParam }, }, }); }; InfiniteQueryObserver.prototype.createResult = function (query, options) { var _a, _b, _c, _d, _e, _f; var state = query.state; var result = _super.prototype.createResult.call(this, query, options); return __assign(__assign({}, result), { fetchNextPage: this.fetchNextPage, fetchPreviousPage: this.fetchPreviousPage, hasNextPage: hasNextPage(options, (_a = state.data) === null || _a === void 0 ? void 0 : _a.pages), hasPreviousPage: hasPreviousPage(options, (_b = state.data) === null || _b === void 0 ? void 0 : _b.pages), isFetchingNextPage: state.isFetching && ((_d = (_c = state.fetchMeta) === null || _c === void 0 ? void 0 : _c.fetchMore) === null || _d === void 0 ? void 0 : _d.direction) === 'forward', isFetchingPreviousPage: state.isFetching && ((_f = (_e = state.fetchMeta) === null || _e === void 0 ? void 0 : _e.fetchMore) === null || _f === void 0 ? void 0 : _f.direction) === 'backward' }); }; return InfiniteQueryObserver; }(QueryObserver)); export { InfiniteQueryObserver };