uses reflection to call the component function
(cfunc any, props map[string]any)
| 193 | |
| 194 | // uses reflection to call the component function |
| 195 | func 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 | |
| 227 | func convertPropsToVDom(props map[string]any) map[string]any { |
| 228 | if len(props) == 0 { |
no test coverage detected