02 - Component Model Examples
This directory contains examples demonstrating BubblyUI's Component Model (Feature 02):
- Component interface and lifecycle
- ComponentBuilder fluent API
- Props system (immutable configuration)
- Setup function (state initialization)
- Template function (rendering)
- Event system (communication)
- Component composition (parent-child)
Examples
Simple button component demonstrating basic component structure, props, and events.
cd button && go run main.go
π’ counter
Counter component with state management using Setup and reactive state.
cd counter && go run main.go
Form component with props, events, and validation logic.
cd form && go run main.go
πͺ nested
Nested components demonstrating composition and parent-child communication.
cd nested && go run main.go
β
todo
Complete todo list application showcasing all component features.
cd todo && go run main.go
Key Concepts
- Component: Encapsulates state, behavior, and presentation
- Props: Immutable configuration passed from parent
- Setup: Initialize reactive state and event handlers
- Template: Render function with access to props and state
- Events: Communication between components (bubbling)
- Composition: Building complex UIs from simple components
Component Lifecycle
- Creation:
NewComponent("Name").Props(...).Setup(...).Template(...).Build()
- Initialization:
component.Init() - Runs setup function
- Update:
component.Update(msg) - Handles Bubbletea messages
- Render:
component.View() - Calls template function
- Event Handling:
component.Emit(event, data) - Triggers event handlers
See Also