A comprehensive example application that demonstrates and tests all major features of the GoFlow framework.
This playground serves as both a feature demonstration and a testing ground for the GoFlow framework. It exercises all core capabilities in a single, well-documented example.
- Counter (int signal)
- Temperature (float64 signal)
- Username (string signal)
- Demonstrates reactive state updates
- Counter doubled (derived from counter)
- Temperature conversion (Celsius to Fahrenheit)
- Greeting message (derived from username)
- Todo count (derived from todo list length)
- Shows automatic recomputation when dependencies change
- Todo list management
- Append, Prepend, RemoveAt operations
- Reactive length computation
- Filter and Map transformations
- Settings management (key-value pairs)
- Update operations
- Reactive map updates
- Text Widget: Simple and styled text rendering
- Container Widget: Layout with padding, margin, colors, sizing
- Column Widget: Vertical layout with alignment
- Center Widget: Centering content
- Padding (symmetric and all-sides)
- Sizing (width/height constraints)
- Colors and backgrounds
- Alignment options
- EdgeInsets (margin/padding)
- Effects for side-effect tracking
- Automatic rebuilds on signal changes
- Batch updates for performance
- Effect cleanup
- Generic signals (int, float64, string, slices, maps)
- Type-safe operations
- Computed signal inference
cd examples/playground
go run main.goThe example will:
- Set up reactive effects to monitor changes
- Build the widget tree
- Run a series of tests demonstrating each feature
- Print detailed output showing reactive updates
- Display final state summary
type PlaygroundApp struct {
// Basic signals
counter *signals.Signal[int]
temperature *signals.Signal[float64]
username *signals.Signal[string]
// Computed signals
counterDoubled *signals.Computed[int]
temperatureInF *signals.Computed[float64]
greeting *signals.Computed[string]
// Collections
todos *signals.SignalSlice[string]
settings *signals.SignalMap[string, bool]
}// Create a signal
counter := signals.New(0)
// Update with a function
counter.Update(func(v int) int { return v + 1 })
// Get the current value
count := counter.Get()// Create a computed signal
doubled := signals.NewComputed(func() int {
return counter.Get() * 2
})
// Automatically updates when counter changes!// Signal slice
todos := signals.NewSlice([]string{"item1", "item2"})
todos.Append("item3")
todos.RemoveAt(0)
// Signal map
settings := signals.NewMap(map[string]bool{"key": true})
settings.Update(func(m map[string]bool) map[string]bool {
m["key"] = !m["key"]
return m
})// Run side effects when signals change
dispose := signals.NewEffect(func() {
count := counter.Get()
fmt.Printf("Counter changed: %d\n", count)
})
defer dispose() // Clean up when donefunc (app *PlaygroundApp) Build(ctx goflow.BuildContext) goflow.Widget {
count := app.counter.Get() // Creates reactive dependency
return widgets.NewCenter(
&widgets.Column{
Children: []goflow.Widget{
widgets.NewText(fmt.Sprintf("Count: %d", count)),
// More widgets...
},
},
)
}When running this example, verify:
- ✅ Signals update correctly
- ✅ Computed signals recalculate automatically
- ✅ Effects trigger on signal changes
- ✅ Collections (slice/map) work reactively
- ✅ Batch updates optimize performance
- ✅ Widget tree builds without errors
- ✅ Layout system handles padding/sizing
- ✅ Colors and styles render correctly
- ✅ Type safety is maintained throughout
After understanding the playground:
- Modify the example - Add your own signals and widgets
- Create custom widgets - Build reusable components
- Experiment with layout - Try different widget compositions
- Add more features - Implement forms, lists, grids
- Build a real app - Use the patterns learned here
This example demonstrates the core GoFlow architecture:
- Widget: Immutable UI descriptions
- Element: Manages widget lifecycle
- RenderObject: Handles layout and painting
- Signals: Reactive state management
- Build: Declarative UI construction
See ARCHITECTURE.md for detailed framework documentation.
goflow-hello: Minimal "Hello World" examplegoflow-counter: Basic counter with interactionstodo-list: Task management appform-validation: Form handling patterns
Found an issue or want to add more tests? Please contribute to make this playground even more comprehensive!