@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
71 lines • 1.93 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, customize, currentKey = "", currentLevel = 0) {
if (customize) {
const result = customize(value, currentKey, currentLevel);
if (result === void 0 && isRef(value)) {
return result;
}
if (result !== void 0) {
return result;
}
}
if (Array.isArray(value)) {
return value.map(
(val, index) => _cloneDeep(val, customize, String(index), currentLevel + 1)
);
}
if (typeof value === "object" && isPlainObject(value)) {
const entries = Object.entries(value).map(([key, val]) => [
key,
_cloneDeep(val, customize, key, currentLevel + 1)
]);
return Object.fromEntries(entries);
}
return value;
}
function cloneDeep(value, customize) {
return _cloneDeep(value, customize);
}
function cloneDeepUnref(obj, unrefGetters = false) {
return cloneDeep(obj, (val, key, level) => {
if (level === 1 && key === "queryKey") {
return cloneDeepUnref(val, true);
}
if (unrefGetters && isFunction(val)) {
return cloneDeepUnref(val(), unrefGetters);
}
if (isRef(val)) {
return cloneDeepUnref(unref(val), unrefGetters);
}
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 isFunction(value) {
return typeof value === "function";
}
export {
VUE_QUERY_CLIENT,
cloneDeep,
cloneDeepUnref,
getClientKey,
updateState
};
//# sourceMappingURL=utils.js.map