Skip to content

Commit d441765

Browse files
committed
debug: Add comprehensive logging to track button clicks and state updates
Add debug logging throughout the event flow to diagnose button click issues: Controls component (controls.gx): - Log when toggle button is clicked - Log before/after sending command to channel App component (app.gx): - Log when command processing goroutine starts - Log each received command - Log state changes (rotationX, rotationY, autoRotate, speed) - Log when state is sent to controlState channel Code generator (codegen.go): - Log when state listener receives updates from channel - Log after app.Update() is called This will help identify where the event flow breaks: 1. Click event fires 2. Command sent to channel 3. Command received and processed 4. State updated 5. State sent to controlState channel 6. Controls receives state update 7. app.Update() triggers re-render
1 parent 5ebb119 commit d441765

7 files changed

Lines changed: 70 additions & 3 deletions

File tree

examples/calculator/calculator_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/counter/counter_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webgpu-cube/app.gx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@ func App() (Component) {
1717
}()
1818

1919
go func() {
20+
log("[App] Command processing goroutine started")
2021
for cmd := range commands {
2122
log(fmt.Sprintf("[App] Received command: %s", cmd.String()))
2223

2324
switch cmd.Type {
2425
case "rotX":
2526
rotationX += float64(cmd.Value)
27+
log(fmt.Sprintf("[App] Updated rotationX to: %.2f", rotationX))
2628
case "rotY":
2729
rotationY += float64(cmd.Value)
30+
log(fmt.Sprintf("[App] Updated rotationY to: %.2f", rotationY))
2831
case "autoRotate":
2932
autoRotate = !autoRotate
33+
log(fmt.Sprintf("[App] Toggled autoRotate to: %t", autoRotate))
3034
case "speed":
3135
speed = float64(cmd.Value)
36+
log(fmt.Sprintf("[App] Updated speed to: %.2f", speed))
3237
}
3338

3439
state := ControlState{AutoRotate: autoRotate, Speed: float32(speed)}
@@ -39,6 +44,7 @@ func App() (Component) {
3944
log("[App] Channel full, skipping state update")
4045
}
4146
}
47+
log("[App] Command processing goroutine ended")
4248
}()
4349

4450
renderUpdate := func(delta float64, rendererInterface interface{}) {

examples/webgpu-cube/app_gen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webgpu-cube/controls.gx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ type ControlState struct {
4545
ID("btn-toggle"),
4646
Class("control-button toggle"),
4747
OnClick(func(e Event) {
48-
commands <- ControlCommand{Type: "autoRotate"}
48+
log("[Controls] Toggle button clicked!")
49+
cmd := ControlCommand{Type: "autoRotate"}
50+
log(fmt.Sprintf("[Controls] Sending command: %s", cmd.String()))
51+
commands <- cmd
52+
log("[Controls] Command sent to channel")
4953
})
5054
) {
5155
if currentState.AutoRotate {

examples/webgpu-cube/controls_gen.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/codegen.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3920,7 +3920,36 @@ func (g *Generator) generateChannelListenerMethods(comp *guixast.Component) []as
39203920
}
39213921

39223922
// Build list of assignments to update in the listener
3923-
updateStmts := []ast.Stmt{}
3923+
updateStmts := []ast.Stmt{
3924+
// Add logging to trace state updates
3925+
&ast.ExprStmt{
3926+
X: &ast.CallExpr{
3927+
Fun: ast.NewIdent("log"),
3928+
Args: []ast.Expr{
3929+
&ast.BinaryExpr{
3930+
X: &ast.BasicLit{
3931+
Kind: token.STRING,
3932+
Value: `"[` + comp.Name + `] Received update from ` + param.Name + ` channel: "`,
3933+
},
3934+
Op: token.ADD,
3935+
Y: &ast.CallExpr{
3936+
Fun: &ast.SelectorExpr{
3937+
X: ast.NewIdent("fmt"),
3938+
Sel: ast.NewIdent("Sprintf"),
3939+
},
3940+
Args: []ast.Expr{
3941+
&ast.BasicLit{
3942+
Kind: token.STRING,
3943+
Value: `"%+v"`,
3944+
},
3945+
ast.NewIdent("val"),
3946+
},
3947+
},
3948+
},
3949+
},
3950+
},
3951+
},
3952+
}
39243953

39253954
// If there's an explicit variable, update it
39263955
if varName != "" {
@@ -3971,6 +4000,18 @@ func (g *Generator) generateChannelListenerMethods(comp *guixast.Component) []as
39714000
},
39724001
},
39734002
},
4003+
// Add logging after update
4004+
&ast.ExprStmt{
4005+
X: &ast.CallExpr{
4006+
Fun: ast.NewIdent("log"),
4007+
Args: []ast.Expr{
4008+
&ast.BasicLit{
4009+
Kind: token.STRING,
4010+
Value: `"[` + comp.Name + `] Called app.Update() after ` + param.Name + ` update"`,
4011+
},
4012+
},
4013+
},
4014+
},
39744015
},
39754016
},
39764017
})

0 commit comments

Comments
 (0)