Compare commits
3 Commits
27f0154bc9
...
d3ed52e4a6
| Author | SHA1 | Date | |
|---|---|---|---|
| d3ed52e4a6 | |||
| f67347688b | |||
| 7cd276a5e5 |
36
examples/counter/main.go
Normal file
36
examples/counter/main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
//go:build js && wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.flowmade.one/flowmade-one/iris/reactive"
|
||||
"git.flowmade.one/flowmade-one/iris/ui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a signal with initial value 0
|
||||
count := reactive.NewSignal(0)
|
||||
|
||||
view := ui.NewView()
|
||||
|
||||
// Reactive text that updates when count changes
|
||||
view.Child(ui.TextFromFunction(func() string {
|
||||
return fmt.Sprintf("Count: %d", count.Get())
|
||||
}))
|
||||
|
||||
// Button that increments the count on click
|
||||
view.Child(ui.Button(func() {
|
||||
count.Set(count.Get() + 1)
|
||||
}, ui.TextFromString("Increment")))
|
||||
|
||||
// Button that decrements the count on click
|
||||
view.Child(ui.Button(func() {
|
||||
count.Set(count.Get() - 1)
|
||||
}, ui.TextFromString("Decrement")))
|
||||
|
||||
ui.NewApp(view)
|
||||
|
||||
select {}
|
||||
}
|
||||
Reference in New Issue
Block a user