@@ -19,8 +19,7 @@ var homeTpl []byte
1919
2020func NewHomeComponent () * core.HTMLComponent {
2121 count := state .NewSignal (0 )
22- c := core .NewComponent ("HomeComponent" , homeTpl , map [string ]any {"count" : count })
23- comp := composition .Wrap (c )
22+ cmp := composition .Wrap (core .NewComponent ("HomeComponent" , homeTpl , map [string ]any {"count" : count }))
2423
2524 var sparkEl dom.Element
2625 var cartEl dom.Element
@@ -77,9 +76,9 @@ func NewHomeComponent() *core.HTMLComponent {
7776 }
7877 }
7978 cart .OnChange ("items" , func (_ any ) { renderCart () })
80- comp .SetOnMount (func (* core.HTMLComponent ) {
81- sparkEl = comp .GetRef ("spark" )
82- cartEl = comp .GetRef ("cart" )
79+ cmp .SetOnMount (func (* core.HTMLComponent ) {
80+ sparkEl = cmp .GetRef ("spark" )
81+ cartEl = cmp .GetRef ("cart" )
8382 renderCart ()
8483 renderDx ()
8584 state .Effect (func () func () {
@@ -97,22 +96,22 @@ func NewHomeComponent() *core.HTMLComponent {
9796 return nil
9897 })
9998 addHandler := state .UseAction (context .Background (), addItem )
100- dom . RegisterHandlerFunc ("add" , func () { _ = addHandler () })
101- dom . RegisterHandlerFunc ("undo" , func () { cart .Undo () })
102- dom . RegisterHandlerFunc ("redo" , func () { cart .Redo () })
103- dom . RegisterHandlerFunc ("inc" , func () { count .Set (count .Get () + 1 ) })
104- dom . RegisterHandlerFunc ("dec" , func () {
99+ cmp . On ("add" , func () { _ = addHandler () })
100+ cmp . On ("undo" , func () { cart .Undo () })
101+ cmp . On ("redo" , func () { cart .Redo () })
102+ cmp . On ("inc" , func () { count .Set (count .Get () + 1 ) })
103+ cmp . On ("dec" , func () {
105104 v := count .Get ()
106105 if v > 0 {
107106 count .Set (v - 1 )
108107 }
109108 })
110109
111- dom . RegisterHandlerFunc ("showRTML" , func () { show ("rtml" ) })
112- dom . RegisterHandlerFunc ("showGO" , func () { show ("go" ) })
113- dom . RegisterHandlerFunc ("showPreview" , func () { show ("preview" ) })
110+ cmp . On ("showRTML" , func () { show ("rtml" ) })
111+ cmp . On ("showGO" , func () { show ("go" ) })
112+ cmp . On ("showPreview" , func () { show ("preview" ) })
114113
115- return c
114+ return cmp . Unwrap ()
116115}
117116
118117func show (target string ) {
0 commit comments