MCPcopy
hub / github.com/wavetermdev/waveterm / callCFunc

Function callCFunc

pkg/vdom/vdom_root.go:380–405  ·  view source on GitHub ↗
(cfunc any, ctx context.Context, props map[string]any)

Source from the content-addressed store, hash-verified

378}
379
380func callCFunc(cfunc any, ctx context.Context, props map[string]any) any {
381 rval := reflect.ValueOf(cfunc)
382 arg2Type := rval.Type().In(1)
383
384 var arg2Val reflect.Value
385 if arg2Type.Kind() == reflect.Interface && arg2Type.NumMethod() == 0 {
386 // For any/interface{}, pass nil properly
387 arg2Val = reflect.New(arg2Type)
388 } else {
389 arg2Val = reflect.New(arg2Type)
390 // if arg2 is a map, just pass props
391 if arg2Type.Kind() == reflect.Map {
392 arg2Val.Elem().Set(reflect.ValueOf(props))
393 } else {
394 err := utilfn.MapToStruct(props, arg2Val.Interface())
395 if err != nil {
396 fmt.Printf("error unmarshalling props: %v\n", err)
397 }
398 }
399 }
400 rtnVal := rval.Call([]reflect.Value{reflect.ValueOf(ctx), arg2Val.Elem()})
401 if len(rtnVal) == 0 {
402 return nil
403 }
404 return rtnVal[0].Interface()
405}
406
407func (r *RootElem) renderComponent(cfunc any, elem *VDomElem, comp **ComponentImpl) {
408 if (*comp).Children != nil {

Callers 1

renderComponentMethod · 0.70

Calls 3

MapToStructFunction · 0.92
TypeMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected