refactor: move cation trigger logic to its own file; separate conter and greeter examples

This commit is contained in:
Joao Goncalves
2025-11-02 02:44:27 -01:00
parent a265f537a6
commit 3d09b3110d
3 changed files with 52 additions and 13 deletions

View File

@@ -15,20 +15,11 @@ func main() {
s := CounterState{Count: 0}
step := c.Signal(1)
greeting := c.Signal("Hello...")
increment := c.Action(func() {
s.Count += step.Int()
c.Sync()
})
greetBob := c.Action(func() {
greeting.SetValue("Hello Bob!")
c.SyncSignals()
})
greetAlice := c.Action(func() {
greeting.SetValue("Hello Alice!")
c.SyncSignals()
})
c.View(func() h.H {
return h.Div(
@@ -39,10 +30,6 @@ func main() {
h.Input(h.Type("number"), step.Bind()),
),
h.Button(h.Text("Increment"), increment.OnClick()),
h.P(h.Span(h.Text("Greeting: ")), h.Span(greeting.Text())),
h.Button(h.Text("Greet Alice"), greetBob.OnClick()),
h.Button(h.Text("Greet Alice"), greetAlice.OnClick()),
)
})
})