Pattern 3
(cfunc any, elem *vdom.VDomElem, comp **ComponentImpl, opts *RenderOpts)
| 86 | |
| 87 | // Pattern 3 |
| 88 | func (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 | |
| 121 | func (r *RootElem) unmount(comp **ComponentImpl) { |
| 122 | if *comp == nil { |
no test coverage detected