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

Function callCFunc

tsunami/engine/render.go:195–225  ·  view source on GitHub ↗

uses reflection to call the component function

(cfunc any, props map[string]any)

Source from the content-addressed store, hash-verified

193
194// uses reflection to call the component function
195func callCFunc(cfunc any, props map[string]any) any {
196 rval := reflect.ValueOf(cfunc)
197 rtype := rval.Type()
198
199 if rtype.NumIn() != 1 {
200 fmt.Printf("component function must have exactly 1 parameter, got %d\n", rtype.NumIn())
201 return nil
202 }
203
204 argType := rtype.In(0)
205
206 var arg1Val reflect.Value
207 if argType.Kind() == reflect.Interface && argType.NumMethod() == 0 {
208 arg1Val = reflect.New(argType)
209 } else {
210 arg1Val = reflect.New(argType)
211 if argType.Kind() == reflect.Map {
212 arg1Val.Elem().Set(reflect.ValueOf(props))
213 } else {
214 err := util.MapToStruct(props, arg1Val.Interface())
215 if err != nil {
216 fmt.Printf("error converting props: %v\n", err)
217 }
218 }
219 }
220 rtnVal := rval.Call([]reflect.Value{arg1Val.Elem()})
221 if len(rtnVal) == 0 {
222 return nil
223 }
224 return rtnVal[0].Interface()
225}
226
227func convertPropsToVDom(props map[string]any) map[string]any {
228 if len(props) == 0 {

Callers 1

callCFuncWithErrorGuardFunction · 0.70

Calls 3

MapToStructFunction · 0.92
TypeMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected