From 0f924d8e8a7d3f74c27d252d43908294c6d3cb3f Mon Sep 17 00:00:00 2001 From: Hugo Nijhuis Date: Fri, 9 Jan 2026 16:59:54 +0100 Subject: [PATCH] Add counter example demonstrating signals Basic example showing: - Creating a signal with NewSignal - Reading value with Get() - Writing value with Set() - Button click handler - Reactive text that updates when signal changes Closes #4 Co-Authored-By: Claude Opus 4.5 --- examples/counter/main.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/counter/main.go diff --git a/examples/counter/main.go b/examples/counter/main.go new file mode 100644 index 0000000..1adcdb6 --- /dev/null +++ b/examples/counter/main.go @@ -0,0 +1,31 @@ +//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"))) + + ui.NewApp(view) + + select {} +}