@@ -12,12 +12,14 @@ import (
1212//go:embed tw.css
1313var styleCSS []byte
1414
15- // Initialize client with embedded Tailwind styles and ctrl-c handling
16- var AppClient = app .MakeClient (app.AppOpts {
17- CloseOnCtrlC : true ,
18- GlobalStyles : styleCSS ,
19- Title : "Todo App (Tsunami Demo)" ,
20- })
15+ func init () {
16+ // Set up the default client with embedded Tailwind styles and ctrl-c handling
17+ app .SetAppOpts (app.AppOpts {
18+ CloseOnCtrlC : true ,
19+ GlobalStyles : styleCSS ,
20+ Title : "Todo App (Tsunami Demo)" ,
21+ })
22+ }
2123
2224// Basic domain types with json tags for props
2325type Todo struct {
@@ -46,7 +48,7 @@ type InputFieldProps struct {
4648}
4749
4850// Reusable input component showing keyboard event handling
49- var InputField = app .DefineComponent (AppClient , "InputField" ,
51+ var InputField = app .DefineComponent ("InputField" ,
5052 func (ctx context.Context , props InputFieldProps ) any {
5153 // Example of special key handling with VDomFunc
5254 keyDown := & vdom.VDomFunc {
@@ -71,7 +73,7 @@ var InputField = app.DefineComponent(AppClient, "InputField",
7173)
7274
7375// Item component showing conditional classes and event handling
74- var TodoItem = app .DefineComponent (AppClient , "TodoItem" ,
76+ var TodoItem = app .DefineComponent ("TodoItem" ,
7577 func (ctx context.Context , props TodoItemProps ) any {
7678 return vdom .H ("div" , map [string ]any {
7779 "className" : vdom .Classes ("flex items-center gap-2.5 p-2 border border-border rounded" , vdom .If (props .Todo .Completed , "opacity-70" )),
@@ -94,7 +96,7 @@ var TodoItem = app.DefineComponent(AppClient, "TodoItem",
9496)
9597
9698// List component demonstrating mapping over data, using WithKey to set key on a component
97- var TodoList = app .DefineComponent (AppClient , "TodoList" ,
99+ var TodoList = app .DefineComponent ("TodoList" ,
98100 func (ctx context.Context , props TodoListProps ) any {
99101 return vdom .H ("div" , map [string ]any {
100102 "className" : "flex flex-col gap-2" ,
@@ -109,7 +111,7 @@ var TodoList = app.DefineComponent(AppClient, "TodoList",
109111)
110112
111113// Root component showing state management and composition
112- var App = app .DefineComponent (AppClient , "App" ,
114+ var App = app .DefineComponent ("App" ,
113115 func (ctx context.Context , _ any ) any {
114116 // Multiple state hooks example
115117 todos , setTodos , _ := vdom .UseState (ctx , []Todo {
@@ -187,5 +189,5 @@ var App = app.DefineComponent(AppClient, "App",
187189)
188190
189191func main () {
190- AppClient .RunMain ()
192+ app .RunMain ()
191193}
0 commit comments