mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
splitted code from function & added decyle to core
This commit is contained in:
parent
5747809cf8
commit
de40ddf1f8
@ -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)
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user