@ace-fetch/vue
Version:
vue adapter for @ace-fetch/core.
44 lines (43 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFetch = void 0;
var vue_demi_1 = require("vue-demi");
var rootFetch_1 = require("./rootFetch");
function createFetch(client) {
var _p = [];
// plugins added before calling app.use(pinia)
var toBeInstalled = [];
var fetch = (0, vue_demi_1.markRaw)({
install: function (app) {
// this allows calling useFetch() outside of a component setup after
(0, rootFetch_1.setActiveFetch)(fetch);
if (!vue_demi_1.isVue2) {
fetch._a = app;
app.provide(rootFetch_1.FetchInjectKey, fetch);
app.config.globalProperties.$afetch = fetch;
app.config.globalProperties.$apiFetch = fetch;
toBeInstalled.forEach(function (plugin) { return _p.push(plugin); });
toBeInstalled = [];
}
},
use: function (plugin) {
if (!this._a && !vue_demi_1.isVue2) {
toBeInstalled.push(plugin);
}
else {
_p.push(plugin);
}
return this;
},
// it's actually undefined here
// @ts-expect-error set in install when using Vue 3
_a: null,
// store regist apis
_r: new Map(),
// regist api plugins
_p: _p,
client: client,
});
return fetch;
}
exports.createFetch = createFetch;