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

Function convertPropsToVDom

tsunami/engine/render.go:227–273  ·  view source on GitHub ↗
(props map[string]any)

Source from the content-addressed store, hash-verified

225}
226
227func convertPropsToVDom(props map[string]any) map[string]any {
228 if len(props) == 0 {
229 return nil
230 }
231 vdomProps := make(map[string]any)
232 for k, v := range props {
233 if v == nil {
234 continue
235 }
236 if vdomFunc, ok := v.(vdom.VDomFunc); ok {
237 // ensure Type is set on all VDomFuncs
238 vdomFunc.Type = vdom.ObjectType_Func
239 vdomProps[k] = vdomFunc
240 continue
241 }
242 if vdomFuncPtr, ok := v.(*vdom.VDomFunc); ok {
243 if vdomFuncPtr == nil {
244 continue // handled typed-nil
245 }
246 // ensure Type is set on all VDomFuncs (pointer)
247 vdomFuncPtr.Type = vdom.ObjectType_Func
248 vdomProps[k] = vdomFuncPtr
249 continue
250 }
251 if vdomRefPtr, ok := v.(*vdom.VDomRef); ok {
252 if vdomRefPtr == nil {
253 continue // handle typed-nil
254 }
255 // ensure Type is set on all VDomRefs (pointer)
256 vdomRefPtr.Type = vdom.ObjectType_Ref
257 vdomProps[k] = vdomRefPtr
258 continue
259 }
260 val := reflect.ValueOf(v)
261 if val.Type() == reflect.TypeOf(vdom.VDomRef{}) {
262 log.Printf("warning: VDomRef passed as non-pointer for prop %q (VDomRef contains atomics and must be passed as *VDomRef); dropping prop\n", k)
263 continue
264 }
265 if val.Kind() == reflect.Func {
266 // convert go functions passed to event handlers to VDomFuncs
267 vdomProps[k] = vdom.VDomFunc{Type: vdom.ObjectType_Func}
268 continue
269 }
270 vdomProps[k] = v
271 }
272 return vdomProps
273}
274
275func (r *RootElem) MakeRendered() *rpctypes.RenderedElem {
276 if r.Root == nil {

Callers 1

convertBaseToRenderedMethod · 0.70

Calls 1

TypeMethod · 0.80

Tested by

no test coverage detected