-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add ComponentTree devtools for DX improvement #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| class ComponentTree { | ||
| constructor() { | ||
| this.tree = {}; | ||
| this.components = new Map(); | ||
| this.enabled = process.env.NODE_ENV === 'development'; | ||
| } | ||
|
|
||
| addComponent(name, instance, parent = null) { | ||
| if (!this.enabled) return; | ||
|
|
||
| const id = `${name}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; | ||
| const componentData = { | ||
| name, | ||
| instance, | ||
| parent, | ||
| id, | ||
| refs: instance.$refs || {}, | ||
| options: instance.$options || {} | ||
| }; | ||
|
|
||
| this.components.set(id, componentData); | ||
|
|
||
| if (!parent) { | ||
| this.tree[id] = { name, children: [] }; | ||
| } else { | ||
| // Parent er children e add korbo | ||
| const parentData = this.components.get(parent); | ||
| if (parentData) { | ||
| if (!parentData.children) parentData.children = []; | ||
| parentData.children.push(componentData); | ||
| } | ||
| } | ||
|
|
||
| console.log(`β Component added: ${name}`, { id, parent }); | ||
| return id; | ||
| } | ||
|
|
||
| removeComponent(id) { | ||
| if (!this.enabled) return; | ||
|
|
||
| const component = this.components.get(id); | ||
| if (component) { | ||
| this.components.delete(id); | ||
| console.log(`β Component removed: ${component.name}`, { id }); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incomplete Component Removal Causes Tree InconsistencyThe |
||
|
|
||
| logTree() { | ||
| if (!this.enabled) return; | ||
|
|
||
| console.group('π³ Component Tree'); | ||
| this.components.forEach((comp, id) => { | ||
| if (!comp.parent) { | ||
| this._logComponent(comp, 0); | ||
| } | ||
| }); | ||
| console.groupEnd(); | ||
| } | ||
|
|
||
| _logComponent(component, depth = 0) { | ||
| const indent = ' '.repeat(depth); | ||
| console.log(`${indent}${component.name} (${component.id})`); | ||
|
|
||
| if (component.children) { | ||
| component.children.forEach(child => { | ||
| this._logComponent(child, depth + 1); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default new ComponentTree(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Redundant Tree Object Causes Inconsistent Data Model
The
this.treeobject is populated for root components but remains unused throughout theComponentTreeclass. The actual component hierarchy, including root and child relationships, is managed and traversed via thethis.componentsMap, makingthis.treeredundant and creating an inconsistent data model.