diff options
author | Sebastian <sebasjm@gmail.com> | 2023-03-11 18:19:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-03-11 18:20:16 -0300 |
commit | c67d94c56e154be4b2cf91572cdc2d8d2da7f8e4 (patch) | |
tree | fbb9444857d4e11f348c051b9c470e9295990096 /packages/web-util | |
parent | b72729f06535f12af974035b141a30320e75575c (diff) | |
download | wallet-core-c67d94c56e154be4b2cf91572cdc2d8d2da7f8e4.tar.xz |
fix: #7753
Diffstat (limited to 'packages/web-util')
-rw-r--r-- | packages/web-util/src/components/utils.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/web-util/src/components/utils.ts b/packages/web-util/src/components/utils.ts index 71824e14f..34693f7d7 100644 --- a/packages/web-util/src/components/utils.ts +++ b/packages/web-util/src/components/utils.ts @@ -34,3 +34,50 @@ export function compose<SType extends { status: string }, PType>( return h(); }; } + +/** + * + * @param obj VNode + * @returns + */ +export function saveVNodeForInspection<T>(obj: T): T { + // @ts-ignore + window["showVNodeInfo"] = function showVNodeInfo() { + inspect(obj); + }; + return obj; +} +function inspect(obj: any) { + if (!obj) return; + if (obj.__c && obj.__c.__H) { + const componentName = obj.__c.constructor.name; + const hookState = obj.__c.__H; + const stateList = hookState.__ as Array<any>; + console.log("==============", componentName); + stateList.forEach((hook) => { + const { __: value, c: context, __h: factory, __H: args } = hook; + if (typeof context !== "undefined") { + const { __c: contextId } = context; + console.log("context:", contextId, hook); + } else if (typeof factory === "function") { + console.log("memo:", value, "deps:", args); + } else if (typeof value === "function") { + const effectName = value.name; + console.log("effect:", effectName, "deps:", args); + } else if (typeof value.current !== "undefined") { + const ref = value.current; + console.log("ref:", ref instanceof Element ? ref.outerHTML : ref); + } else if (value instanceof Array) { + console.log("state:", value[0]); + } else { + console.log(hook); + } + }); + } + const children = obj.__k; + if (children instanceof Array) { + children.forEach((e) => inspect(e)); + } else { + inspect(children); + } +} |