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

Function findComponent

packages/debugger/src/structure/walker.ts:179–212  ·  view source on GitHub ↗
(
    r: ComponentRegistry<TEl>,
    el: TEl,
)

Source from the content-addressed store, hash-verified

177
178export
179const findComponent = <TEl extends object>(
180 r: ComponentRegistry<TEl>,
181 el: TEl,
182): ComponentData<TEl> | null => {
183
184 let including = new Map<Solid.Owner, ComponentData<TEl>>()
185
186 for (let curr: TEl | null = el;
187 curr != null && including.size === 0;
188 ) {
189 for (let comp of r.components.values()) {
190 for (let comp_el of comp.elements) {
191 if (comp_el === curr) {
192 including.set(comp.owner, comp)
193 }
194 }
195 }
196 curr = r.eli.getParent(curr) // go up
197 }
198
199 if (including.size > 1) {
200 // find the closest component
201 for (let owner of including.keys()) {
202 if (including.has(owner)) {
203 for (let curr = owner.owner; curr != null;) {
204 if (including.delete(curr)) break
205 curr = curr.owner // go up
206 }
207 }
208 }
209 }
210
211 return including.values().next().value ?? null
212}
213
214
215export

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…