README
¶
Example 01: Basic Enablement
Zero-config dev tools getting started
What This Demonstrates
This example shows the absolute simplest way to enable dev tools in a BubblyUI application:
- Zero-Config Enablement - Just call
devtools.Enable() - Component Architecture - Composable components pattern
- Component Tree - Hierarchical component structure
- State Inspection - Reactive state visible in dev tools
- Composables - Reusable reactive logic (UseCounter)
Architecture
Directory Structure
01-basic-enablement/
├── main.go # Entry point with devtools.Enable()
├── app.go # Root component (CounterApp)
├── components/ # UI components
│ ├── counter_display.go # Display component (shows count)
│ └── counter_controls.go # Control hints component
├── composables/ # Reusable logic
│ └── use_counter.go # Counter composable
└── README.md # This file
Component Hierarchy
CounterApp (root)
├── CounterDisplay (shows current count and parity)
└── CounterControls (shows keyboard shortcuts)
State Flow
UseCounter (composable)
├── count (Ref[int]) ← Reactive state
├── isEven (Computed[bool]) ← Derived from count
└── methods (increment, decrement, reset)
Key Features
1. Zero-Config Enablement
// main.go
func main() {
devtools.Enable() // That's it!
// Rest of your app...
}
No configuration needed. Dev tools work out of the box.
2. Composable Pattern
// composables/use_counter.go
func UseCounter(ctx *bubbly.Context, initial int) *CounterComposable {
count := bubbly.NewRef(initial)
isEven := ctx.Computed(func() interface{} {
return count.Get().(int)%2 == 0
})
return &CounterComposable{
Count: count,
IsEven: isEven,
Increment: func() { /* ... */ },
// ...
}
}
Reusable reactive logic that can be shared across components.
3. Component Factory Pattern
// components/counter_display.go
func CreateCounterDisplay(props CounterDisplayProps) (bubbly.Component, error) {
builder := bubbly.NewComponent("CounterDisplay")
builder = builder.Setup(func(ctx *bubbly.Context) {
ctx.Expose("count", props.Count)
ctx.Expose("isEven", props.IsEven)
})
builder = builder.Template(func(ctx bubbly.RenderContext) string {
// Render using BubblyUI components
})
return builder.Build()
}
Clean, testable component creation.
4. State Exposure for Dev Tools
// app.go
builder = builder.Setup(func(ctx *bubbly.Context) {
counter := composables.UseCounter(ctx, 0)
// Expose state for dev tools inspection
ctx.Expose("counter", counter)
// ...
})
All exposed state is visible in dev tools.
Run the Example
cd 01-basic-enablement
go run main.go
Using Dev Tools
Toggle Visibility
Press F12 to show/hide dev tools panel.
Component Tree
- Use
↑/↓to navigate components - Use
→/←to expand/collapse nodes - Press
Enterto view component details
State Inspection
- Press
Tabto switch to State tab - See all reactive state:
counter.Count(Ref[int])counter.IsEven(Computed[bool])
- Watch values update as you interact
Try It Out
- Press
ito increment (count goes up) - Press
dto decrement (count goes down) - Press
rto reset (count returns to 0) - Watch dev tools update in real-time!
What to Notice
Component Tree
CounterApp
├── CounterDisplay (*) ← You'll see this
└── CounterControls ← And this
Both components appear in the tree, with their state visible.
Reactive State
counter.Count: 0 ← Changes when you press i/d/r
counter.IsEven: true ← Auto-updates when count changes
Computed values update automatically!
Lifecycle Events
Open your terminal console to see:
[CounterDisplay] Mounted - visible in dev tools!
Lifecycle hooks fire and are visible.
Code Highlights
Composable Reuse
The UseCounter composable encapsulates ALL counter logic:
- State management (Ref)
- Derived values (Computed)
- Methods (increment, decrement, reset)
This can be reused in ANY component that needs counter functionality.
Component Composition
The app composes smaller components:
CounterDisplayhandles display logicCounterControlsshows shortcutsCounterAppcoordinates them
Each component is focused and testable.
BubblyUI Components
We use framework components, not manual rendering:
components.Card()for the counter displaycomponents.Text()for help text
No hardcoded Lipgloss styles!
Next Steps
After understanding this example:
- Explore component tree - Navigate the hierarchy with keyboard
- Watch state changes - See reactive updates in real-time
- Read the architecture guide - Composable Apps Guide
- Try example 02 - More complex component hierarchy
Related Documentation
Troubleshooting
Dev tools not showing?
- Make sure you called
devtools.Enable()before creating components - Press
F12to toggle visibility
Can't see state?
- Check that you're exposing state with
ctx.Expose() - Switch to the State tab in dev tools
Component not in tree?
- Verify
ExposeComponent()was called - Check component was created successfully (no errors)
Documentation
¶
There is no documentation for this package.