splitted code from function & added decyle to core

This commit is contained in:
srgooglo 2020-10-28 18:15:21 +01:00
parent 5747809cf8
commit de40ddf1f8
2 changed files with 140 additions and 146 deletions

View File

@ -1,10 +1,7 @@
import React from 'react';
import * as antd from 'antd'
import * as Icons from 'components/Icons'
import { __legacy__objectToArray } from 'core'
export default function DebugPanel(data) {
import { __legacy__objectToArray, getCircularReplacer, decycle } from 'core'
const serializeFlags = {
__cycle_flag: true // with id 0
@ -14,36 +11,6 @@ export default function DebugPanel(data) {
return serializeFlags[Object.keys(e)[id ?? 0]]
}
function getCircularReplacer() {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return { __cycle_flag: true }
}
seen.add(value)
}
return value
}
}
function decycle(obj, stack = []) {
if (!obj || typeof obj !== 'object')
return obj;
if (stack.includes(obj)) {
return { __cycle_flag: true }
}
let s = stack.concat([obj]);
return Array.isArray(obj)
? obj.map(x => decycle(x, s))
: Object.fromEntries(
Object.entries(obj)
.map(([k, v]) => [k, decycle(v, s)]));
}
const getErrorRender = (e, error) => {
return (
<div key={e.key} >
@ -137,8 +104,6 @@ export default function DebugPanel(data) {
}
}
const modelToMap = (data) => {
if (!data) return false
const getType = (e) => {
if (e !== null && isFlagId(e, 0)) {
return `[loop]`
@ -146,6 +111,8 @@ export default function DebugPanel(data) {
return `[${typeof (e)}]`
}
export default function DebugPanel(data) {
if (!data) return false
return __legacy__objectToArray(decycle(data)).map(e => {
try {
const content = getContent(e)
@ -163,6 +130,3 @@ export default function DebugPanel(data) {
}
})
}
return modelToMap(data)
}

View File

@ -34,6 +34,36 @@ export const clientInfo = {
layout: platform.layout
};
export function getCircularReplacer() {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return { __cycle_flag: true }
}
seen.add(value)
}
return value
}
}
export function decycle(obj, stack = []) {
if (!obj || typeof obj !== 'object')
return obj;
if (stack.includes(obj)) {
return { __cycle_flag: true }
}
let s = stack.concat([obj]);
return Array.isArray(obj)
? obj.map(x => decycle(x, s))
: Object.fromEntries(
Object.entries(obj)
.map(([k, v]) => [k, decycle(v, s)]));
}
export function getBuild() {
let build = {
stable: false