You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tsunami/prompts/system.md
+55-15Lines changed: 55 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -633,12 +633,20 @@ Best Practices:
633
633
634
634
## State Management and Async Updates
635
635
636
-
While React patterns typically avoid globals, in Go Tsunami applications it's perfectly fine and often clearer to use global variables. However, when dealing with async operations and goroutines, special care must be taken:
636
+
For global state management, use the atoms system (SharedAtom, Config, or Data as appropriate). This provides global reactive state that components can subscribe to:
637
637
638
638
```go
639
-
// Global state is fine!
640
-
varglobalTodos []Todo
641
-
varglobalFilterstring
639
+
// Use func init() to set atom defaults
640
+
funcinit() {
641
+
app.SetData("todos", []Todo{})
642
+
app.SetConfig("filter", "")
643
+
}
644
+
645
+
typeTodostruct {
646
+
Idint`json:"id"`
647
+
Textstring`json:"text"`
648
+
Donebool`json:"done"`
649
+
}
642
650
643
651
// For async operations, consider using a state struct
644
652
typeTimerStatestruct {
@@ -649,11 +657,12 @@ type TimerState struct {
649
657
650
658
varTodoApp = app.DefineComponent("TodoApp",
651
659
func(ctx context.Context, _ struct{}) any {
652
-
// Local state for UI updates
653
-
count, setCount:= vdom.UseState(ctx, 0)
660
+
// Use atoms for global state (prefixes must match init functions)
0 commit comments