@@ -5,8 +5,8 @@ package components
55import (
66 _ "embed"
77
8+ "github.com/rfwlab/rfw/v1/composition"
89 core "github.com/rfwlab/rfw/v1/core"
9- dom "github.com/rfwlab/rfw/v1/dom"
1010)
1111
1212//go:embed templates/event_component.rtml
@@ -15,17 +15,18 @@ var eventComponentTpl []byte
1515// EventComponent demonstrates both basic event handling and event modifiers.
1616// EventComponent demonstrates both basic event handling and event modifiers.
1717func NewEventComponent () * core.HTMLComponent {
18- c := core .NewComponent ("EventComponent" , eventComponentTpl , nil )
18+ cmp := composition . Wrap ( core .NewComponent ("EventComponent" , eventComponentTpl , nil ) )
1919
20- if c .Store .Get ("count" ) == nil {
21- c .Store .Set ("count" , 0 )
20+ store := cmp .HTMLComponent .Store
21+ if store .Get ("count" ) == nil {
22+ store .Set ("count" , 0 )
2223 }
2324
2425 // register increment so buttons in the template can call it
25- dom . RegisterHandlerFunc ("increment" , func () {
26- if val , ok := c . Store .Get ("count" ).(int ); ok {
27- c . Store .Set ("count" , val + 1 )
26+ cmp . On ("increment" , func () {
27+ if val , ok := store .Get ("count" ).(int ); ok {
28+ store .Set ("count" , val + 1 )
2829 }
2930 })
30- return c
31+ return cmp . Unwrap ()
3132}
0 commit comments