MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / renderChildren

Method renderChildren

tsunami/engine/render.go:151–180  ·  view source on GitHub ↗

handles reconcilation maps children via key or index (exclusively)

(elems []vdom.VDomElem, curChildren []*ComponentImpl, containingComp string, opts *RenderOpts)

Source from the content-addressed store, hash-verified

149// handles reconcilation
150// maps children via key or index (exclusively)
151func (r *RootElem) renderChildren(elems []vdom.VDomElem, curChildren []*ComponentImpl, containingComp string, opts *RenderOpts) []*ComponentImpl {
152 newChildren := make([]*ComponentImpl, len(elems))
153 curCM := make(map[ChildKey]*ComponentImpl)
154 usedMap := make(map[*ComponentImpl]bool)
155 for idx, child := range curChildren {
156 if child.Key != "" {
157 curCM[ChildKey{Tag: child.Tag, Idx: 0, Key: child.Key}] = child
158 } else {
159 curCM[ChildKey{Tag: child.Tag, Idx: idx, Key: ""}] = child
160 }
161 }
162 for idx, elem := range elems {
163 elemKey := getElemKey(&elem)
164 var curChild *ComponentImpl
165 if elemKey != "" {
166 curChild = curCM[ChildKey{Tag: elem.Tag, Idx: 0, Key: elemKey}]
167 } else {
168 curChild = curCM[ChildKey{Tag: elem.Tag, Idx: idx, Key: ""}]
169 }
170 usedMap[curChild] = true
171 newChildren[idx] = curChild
172 r.render(&elem, &newChildren[idx], containingComp, opts)
173 }
174 for _, child := range curChildren {
175 if !usedMap[child] {
176 r.unmount(&child)
177 }
178 }
179 return newChildren
180}
181
182// safely calls the component function with panic recovery
183func callCFuncWithErrorGuard(cfunc any, props map[string]any, componentName string) (result any) {

Callers 1

renderSimpleMethod · 0.95

Calls 3

renderMethod · 0.95
unmountMethod · 0.95
getElemKeyFunction · 0.85

Tested by

no test coverage detected