mirror of https://github.com/rancher/dashboard.git
Add deepToRaw method for recursively converting proxy objects to raw
This commit is contained in:
parent
e2731ebb08
commit
2b55944791
|
|
@ -13,6 +13,7 @@ import {
|
|||
import { perfLoadAll } from '@shell/plugins/steve/performanceTesting';
|
||||
import { classify } from '@shell/plugins/dashboard-store/classify';
|
||||
import SteveSchema from '@shell/models/steve-schema';
|
||||
import { deepToRaw } from '@shell/utils/object';
|
||||
|
||||
function registerNamespace(state, namespace) {
|
||||
let cache = state.podsByNamespace[namespace];
|
||||
|
|
@ -145,7 +146,9 @@ export default {
|
|||
|
||||
if (worker) {
|
||||
// Store raw json objects, not the proxies
|
||||
worker.postMessage({ loadSchemas: data });
|
||||
const rawData = deepToRaw(data);
|
||||
|
||||
worker.postMessage({ loadSchemas: rawData });
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { toRaw } from 'vue';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import flattenDeep from 'lodash/flattenDeep';
|
||||
import compact from 'lodash/compact';
|
||||
|
|
@ -434,3 +435,35 @@ export function dropKeys(obj, keys) {
|
|||
delete obj[k];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively convert a reactive object to a raw object
|
||||
* @param {*} obj
|
||||
* @param {*} cache
|
||||
* @returns
|
||||
*/
|
||||
export function deepToRaw(obj, cache = new WeakSet()) {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
// If obj is null or a primitive, return it as is
|
||||
return obj;
|
||||
}
|
||||
|
||||
// If the object has already been processed, return it to prevent circular references
|
||||
if (cache.has(obj)) {
|
||||
return obj;
|
||||
}
|
||||
cache.add(obj);
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => deepToRaw(item, cache));
|
||||
} else {
|
||||
const rawObj = toRaw(obj);
|
||||
const result = {};
|
||||
|
||||
for (const key in rawObj) {
|
||||
result[key] = deepToRaw(rawObj[key], cache);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue