@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
64 lines • 1.59 kB
JavaScript
// src/utils.ts
import { isRef, unref } from "vue-demi";
var VUE_QUERY_CLIENT = "VUE_QUERY_CLIENT";
function getClientKey(key) {
const suffix = key ? `:${key}` : "";
return `${VUE_QUERY_CLIENT}${suffix}`;
}
function updateState(state, update) {
Object.keys(state).forEach((key) => {
state[key] = update[key];
});
}
function cloneDeep(value, customizer) {
if (customizer) {
const result = customizer(value);
if (result === void 0 && isRef(value)) {
return result;
}
if (result !== void 0) {
return result;
}
}
if (Array.isArray(value)) {
return value.map((val) => cloneDeep(val, customizer));
}
if (typeof value === "object" && isPlainObject(value)) {
const entries = Object.entries(value).map(([key, val]) => [
key,
cloneDeep(val, customizer)
]);
return Object.fromEntries(entries);
}
return value;
}
function cloneDeepUnref(obj) {
return cloneDeep(obj, (val) => {
if (isRef(val)) {
return cloneDeepUnref(unref(val));
}
return void 0;
});
}
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== "[object Object]") {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
}
function shouldThrowError(throwOnError, params) {
if (typeof throwOnError === "function") {
return throwOnError(...params);
}
return !!throwOnError;
}
export {
VUE_QUERY_CLIENT,
cloneDeep,
cloneDeepUnref,
getClientKey,
shouldThrowError,
updateState
};
//# sourceMappingURL=utils.js.map