UNPKG

@antdv/pro-utils

Version:

@antdv/pro-utils

65 lines (64 loc) 2.31 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var stdin_exports = {}; __export(stdin_exports, { useFetchData: () => useFetchData }); module.exports = __toCommonJS(stdin_exports); var import_vue = require("vue"); var import_useRequest = require("../useRequest"); function useFetchData(props) { const abortRef = (0, import_vue.ref)(null); const { state, error } = (0, import_useRequest.useRequest)(() => __async(this, null, function* () { var _a, _b; (_a = abortRef.value) == null ? void 0 : _a.abort(); const abort = new AbortController(); abortRef.value = abort; const loadData = yield Promise.race([ (_b = props.request) == null ? void 0 : _b.call(props, props.params, props), new Promise((_, reject) => { var _a2, _b2; (_b2 = (_a2 = abortRef.value) == null ? void 0 : _a2.signal) == null ? void 0 : _b2.addEventListener("abort", () => { reject(new Error("aborted")); }); }) ]); return loadData; })); return [state || error]; }