MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / createStructure

Function createStructure

packages/frontend/src/structure.tsx:73–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71}
72
73export function createStructure() {
74 const ctx = useAppCtx()
75 const cachedInitialState = ctx.viewCache.get(debug.DevtoolsMainView.Structure)
76
77 const [mode, setMode] = s.createSignal<debug.TreeWalkerMode>(
78 cachedInitialState.long?.mode ?? debug.DEFAULT_WALKER_MODE,
79 )
80
81 function changeTreeViewMode(newMode: debug.TreeWalkerMode): void {
82 if (newMode === mode()) return
83 s.batch(() => {
84 setMode(newMode)
85 search('')
86 })
87 }
88
89 function getStateNull(): State {
90 return {
91 nodeList: [],
92 roots: [],
93 }
94 }
95
96 const [state, setState] = s.createSignal<State>(
97 cachedInitialState.short || getStateNull(),
98 )
99 ctx.viewCache.set(debug.DevtoolsMainView.Structure, () => ({
100 short: state(),
101 long: {mode: mode()},
102 }))
103
104 const inspectedNode = s.createMemo(() => {
105 const id = ctx.inspector.inspected.treeWalkerOwnerId
106 return id ? findNode(id) : null
107 })
108
109 function updateStructure(update: debug.StructureUpdates | null): void {
110 setState(prev =>
111 update ? reconcileStructure(prev.roots, update) : getStateNull(),
112 )
113 }
114
115 function findNode(id: debug.NodeID): Node | undefined {
116 for (const node of state().nodeList) {
117 if (node.id === id) return node
118 }
119 }
120
121 const [searchResult, setSearchResult] = s.createSignal<debug.NodeID[]>()
122 const isSearched = s.createSelector(searchResult, (node: debug.NodeID, o) => !!o && o.includes(node))
123
124 function searchNodeList(query: string): debug.NodeID[] | undefined {
125 if (!query) return setSearchResult()
126 return s.untrack(() => {
127 const result: debug.NodeID[] = []
128 const rgx = new RegExp('^' + query, 'i')
129 for (const node of state().nodeList) {
130 if (node.type !== debug.NodeType.Element && node.name && node.name.match(rgx))

Callers 1

StructureViewFunction · 0.70

Calls 6

useAppCtxFunction · 0.90
msgFunction · 0.90
getStateNullFunction · 0.85
findNodeFunction · 0.85
updateStructureFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…