@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
105 lines (104 loc) • 3.55 kB
JavaScript
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);
// src/vueQueryPlugin.ts
var vueQueryPlugin_exports = {};
__export(vueQueryPlugin_exports, {
VueQueryPlugin: () => VueQueryPlugin
});
module.exports = __toCommonJS(vueQueryPlugin_exports);
var import_vue_demi = require("vue-demi");
var import_query_core = require("@tanstack/query-core");
var import_queryClient = require("./queryClient.cjs");
var import_utils = require("./utils.cjs");
var import_devtools = require("./devtools/devtools.cjs");
var VueQueryPlugin = {
install: (app, options = {}) => {
const clientKey = (0, import_utils.getClientKey)(options.queryClientKey);
let client;
if ("queryClient" in options && options.queryClient) {
client = options.queryClient;
} else {
const clientConfig = "queryClientConfig" in options ? options.queryClientConfig : void 0;
client = new import_queryClient.QueryClient(clientConfig);
}
if (!import_query_core.isServer) {
client.mount();
}
let persisterUnmount = () => {
};
if (options.clientPersister) {
if (client.isRestoring) {
client.isRestoring.value = true;
}
const [unmount, promise] = options.clientPersister(client);
persisterUnmount = unmount;
promise.then(() => {
var _a;
if (client.isRestoring) {
client.isRestoring.value = false;
}
(_a = options.clientPersisterOnSuccess) == null ? void 0 : _a.call(options, client);
});
}
const cleanup = () => {
client.unmount();
persisterUnmount();
};
if (app.onUnmount) {
app.onUnmount(cleanup);
} else {
const originalUnmount = app.unmount;
app.unmount = function vueQueryUnmount() {
cleanup();
originalUnmount();
};
}
if (import_vue_demi.isVue2) {
app.mixin({
beforeCreate() {
if (!this._provided) {
const provideCache = {};
Object.defineProperty(this, "_provided", {
get: () => provideCache,
set: (v) => Object.assign(provideCache, v)
});
}
this._provided[clientKey] = client;
if (process.env.NODE_ENV === "development") {
if (this === this.$root && options.enableDevtoolsV6Plugin) {
(0, import_devtools.setupDevtools)(this, client);
}
}
}
});
} else {
app.provide(clientKey, client);
if (process.env.NODE_ENV === "development") {
if (options.enableDevtoolsV6Plugin) {
(0, import_devtools.setupDevtools)(app, client);
}
}
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
VueQueryPlugin
});
//# sourceMappingURL=vueQueryPlugin.cjs.map
;