MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / renderComponent

Method renderComponent

tsunami/engine/render.go:88–119  ·  view source on GitHub ↗

Pattern 3

(cfunc any, elem *vdom.VDomElem, comp **ComponentImpl, opts *RenderOpts)

Source from the content-addressed store, hash-verified

86
87// Pattern 3
88func (r *RootElem) renderComponent(cfunc any, elem *vdom.VDomElem, comp **ComponentImpl, opts *RenderOpts) {
89 if (*comp).Children != nil {
90 // Clear Children since custom components don't use them
91 for _, child := range (*comp).Children {
92 r.unmount(&child)
93 }
94 (*comp).Children = nil
95 }
96 props := make(map[string]any)
97 for k, v := range elem.Props {
98 props[k] = v
99 }
100 props[ChildrenPropKey] = elem.Children
101 vc := makeContextVal(r, *comp, opts)
102 rtnElemArr := withGlobalRenderCtx(vc, func() []vdom.VDomElem {
103 renderedElem := callCFuncWithErrorGuard(cfunc, props, elem.Tag)
104 return vdom.ToElems(renderedElem)
105 })
106
107 // Process atom usage after render
108 r.updateComponentAtomUsage(*comp, vc.UsedAtoms)
109
110 var rtnElem *vdom.VDomElem
111 if len(rtnElemArr) == 0 {
112 rtnElem = nil
113 } else if len(rtnElemArr) == 1 {
114 rtnElem = &rtnElemArr[0]
115 } else {
116 rtnElem = &vdom.VDomElem{Tag: vdom.FragmentTag, Children: rtnElemArr}
117 }
118 r.render(rtnElem, &(*comp).RenderedComp, elem.Tag, opts)
119}
120
121func (r *RootElem) unmount(comp **ComponentImpl) {
122 if *comp == nil {

Callers 1

renderMethod · 0.95

Calls 7

unmountMethod · 0.95
renderMethod · 0.95
ToElemsFunction · 0.92
makeContextValFunction · 0.85
withGlobalRenderCtxFunction · 0.85
callCFuncWithErrorGuardFunction · 0.85

Tested by

no test coverage detected