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,50 +1,17 @@
|
||||
import React from 'react';
|
||||
import * as antd from 'antd'
|
||||
import * as Icons from 'components/Icons'
|
||||
import { __legacy__objectToArray } from 'core'
|
||||
import { __legacy__objectToArray, getCircularReplacer, decycle } from 'core'
|
||||
|
||||
|
||||
export default function DebugPanel(data) {
|
||||
|
||||
const serializeFlags = {
|
||||
const serializeFlags = {
|
||||
__cycle_flag: true // with id 0
|
||||
}
|
||||
}
|
||||
|
||||
function isFlagId(e, id) {
|
||||
function isFlagId(e, id) {
|
||||
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) => {
|
||||
const getErrorRender = (e, error) => {
|
||||
return (
|
||||
<div key={e.key} >
|
||||
<div style={{ display: "flex", alignItems: "center", padding: "12px 16px", height: "47px", backgroundColor: "#d9d9d9" }} key={e.key} >
|
||||
@ -61,9 +28,9 @@ export default function DebugPanel(data) {
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const getDecoratorStr = (e, json) => {
|
||||
const getDecoratorStr = (e, json) => {
|
||||
try {
|
||||
switch (typeof (e.value)) {
|
||||
case "string": {
|
||||
@ -99,9 +66,9 @@ export default function DebugPanel(data) {
|
||||
} catch (error) {
|
||||
return <strong>Immeasurable (by error)</strong>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getContent = (e) => {
|
||||
const getContent = (e) => {
|
||||
try {
|
||||
switch (typeof (e.value)) {
|
||||
case "string": {
|
||||
@ -135,17 +102,17 @@ export default function DebugPanel(data) {
|
||||
} catch (error) {
|
||||
return getErrorRender(e, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const modelToMap = (data) => {
|
||||
if (!data) return false
|
||||
const getType = (e) => {
|
||||
const getType = (e) => {
|
||||
if (e !== null && isFlagId(e, 0)) {
|
||||
return `[loop]`
|
||||
}
|
||||
return `[${typeof (e)}]`
|
||||
}
|
||||
}
|
||||
|
||||
export default function DebugPanel(data) {
|
||||
if (!data) return false
|
||||
return __legacy__objectToArray(decycle(data)).map(e => {
|
||||
try {
|
||||
const content = getContent(e)
|
||||
@ -162,7 +129,4 @@ export default function DebugPanel(data) {
|
||||
return getErrorRender(e, error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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