~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


00f837a1 Peter John

tag: v0.17.2

v0.17.2

3 years ago
add default props
Files changed (1) hide show
  1. http.go +7 -1
http.go CHANGED
@@ -81,6 +81,7 @@ func RegisterComponent(fn any, props ...string) {
81
81
  for i := 0; i < structType.NumField(); i++ {
82
82
  if f := rv.Field(i); f.CanSet() {
83
83
  jsonName := structType.Field(i).Tag.Get("json")
84
+ defaultValue := structType.Field(i).Tag.Get("default")
84
85
  if jsonName == "children" {
85
86
  s, err := help.Block()
86
87
  if err != nil {
@@ -88,7 +89,12 @@ func RegisterComponent(fn any, props ...string) {
88
89
  }
89
90
  f.Set(reflect.ValueOf(template.HTML(s)))
90
91
  } else {
92
+ v := help.Context.Get(jsonName)
93
+ if v == nil {
91
- f.Set(reflect.ValueOf(help.Context.Get(jsonName)))
94
+ f.Set(reflect.ValueOf(defaultValue))
95
+ } else {
96
+ f.Set(reflect.ValueOf(v))
97
+ }
92
98
  }
93
99
  }
94
100
  }