Documentation
¶
Overview ¶
Package composables provides Vue-inspired composable functions for BubblyUI.
Composables are reusable functions that encapsulate stateful logic using the Composition API pattern. They provide a clean way to extract and share reactive state management across components.
This package is an alias for github.com/newbpydev/bubblyui/pkg/bubbly/composables, providing a cleaner import path for users.
Core Composables ¶
- UseState: Simple reactive state with getter/setter
- UseEffect: Side effects with automatic cleanup
- UseDebounce: Debounced reactive values
- UseThrottle: Throttled callback execution
- UseEventListener: Event subscription management
Data Composables ¶
- UseList: Reactive list operations (add, remove, filter)
- UseHistory: Undo/redo state management
- UseForm: Form state with validation
- UseLocalStorage: Persistent storage integration
UI Composables ¶
- UseFocus: Focus management with tab order
- UseWindowSize: Responsive breakpoint tracking
- UseCounter: Numeric counter with min/max/step
- UseInterval: Periodic callback execution
Example ¶
import "github.com/newbpydev/bubblyui/composables"
func setup(ctx *bubbly.Context) {
// State management
count := composables.UseState(ctx, 0)
count.Set(count.Get() + 1)
// Debounced search
query := bubbly.NewRef("")
debouncedQuery := composables.UseDebounce(ctx, query, 300*time.Millisecond)
// Focus management
focus := composables.UseFocus(ctx, "input1", []string{"input1", "input2", "submit"})
}
Index ¶
- Constants
- Variables
- func CreateShared[T any](factory func(*bubbly.Context) T) func(*bubbly.Context) T
- func UseDebounce[T any](ctx *bubbly.Context, value *bubbly.Ref[T], delay time.Duration) *bubbly.Ref[T]
- type Breakpoint
- type BreakpointConfig
- type CounterOption
- type CounterReturn
- type FileStorage
- type FocusReturn
- type HistoryReturn
- type IntervalReturn
- type ListReturn
- type LogEntry
- type LogLevel
- type LoggerReturn
- type Storage
- type UseAsyncReturn
- type UseEffectCleanup
- type UseFormReturn
- type UseStateReturn
- type WindowSizeReturn
Constants ¶
const ( BreakpointXS = composables.BreakpointXS BreakpointSM = composables.BreakpointSM BreakpointMD = composables.BreakpointMD BreakpointLG = composables.BreakpointLG BreakpointXL = composables.BreakpointXL )
Breakpoint constants for responsive design.
const ( LogLevelDebug = composables.LogLevelDebug LogLevelInfo = composables.LogLevelInfo LogLevelWarn = composables.LogLevelWarn LogLevelError = composables.LogLevelError )
Log level constants.
Variables ¶
var BlinkCmd = composables.BlinkCmd
BlinkCmd returns a Bubbletea command for cursor blinking.
var ErrComposableOutsideSetup = composables.ErrComposableOutsideSetup
ErrComposableOutsideSetup is returned when a composable is used outside Setup.
var NewFileStorage = composables.NewFileStorage
NewFileStorage creates a new file-based storage.
var UseCounter = composables.UseCounter
UseCounter provides a numeric counter with min/max/step options.
var UseEffect = composables.UseEffect
UseEffect registers a side effect that runs when dependencies change.
var UseEventListener = composables.UseEventListener
UseEventListener registers an event listener with automatic cleanup.
var UseInterval = composables.UseInterval
UseInterval provides periodic callback execution.
var UseLogger = composables.UseLogger
UseLogger provides component logging utilities.
var UseThrottle = composables.UseThrottle
UseThrottle creates a throttled version of a callback function.
var UseWindowSize = composables.UseWindowSize
UseWindowSize provides responsive breakpoint tracking.
var WithMax = composables.WithMax
WithMax sets the maximum value for the counter.
var WithMin = composables.WithMin
WithMin sets the minimum value for the counter.
var WithStep = composables.WithStep
WithStep sets the increment/decrement step for the counter.
Functions ¶
func CreateShared ¶
CreateShared creates a shared composable instance across components.
Types ¶
type Breakpoint ¶
type Breakpoint = composables.Breakpoint
Breakpoint represents a responsive breakpoint.
type BreakpointConfig ¶
type BreakpointConfig = composables.BreakpointConfig
BreakpointConfig configures responsive breakpoints.
type CounterOption ¶
type CounterOption = composables.CounterOption
CounterOption configures UseCounter behavior.
type CounterReturn ¶
type CounterReturn = composables.CounterReturn
CounterReturn is the return type for UseCounter.
type FileStorage ¶
type FileStorage = composables.FileStorage
FileStorage provides file-based storage implementation.
type FocusReturn ¶
type FocusReturn[T comparable] = composables.FocusReturn[T]
FocusReturn is the return type for UseFocus.
func UseFocus ¶
func UseFocus[T comparable](ctx *bubbly.Context, initial T, order []T) *FocusReturn[T]
UseFocus provides focus management with tab order.
type HistoryReturn ¶
type HistoryReturn[T any] = composables.HistoryReturn[T]
HistoryReturn is the return type for UseHistory.
func UseHistory ¶
func UseHistory[T any](ctx *bubbly.Context, initial T, maxSize int) *HistoryReturn[T]
UseHistory provides undo/redo state management.
type IntervalReturn ¶
type IntervalReturn = composables.IntervalReturn
IntervalReturn is the return type for UseInterval.
type ListReturn ¶
type ListReturn[T any] = composables.ListReturn[T]
ListReturn is the return type for UseList.
type LoggerReturn ¶
type LoggerReturn = composables.LoggerReturn
LoggerReturn is the return type for UseLogger.
type Storage ¶
type Storage = composables.Storage
Storage defines the interface for persistent storage.
type UseAsyncReturn ¶
type UseAsyncReturn[T any] = composables.UseAsyncReturn[T]
UseAsyncReturn is the return type for UseAsync.
type UseEffectCleanup ¶
type UseEffectCleanup = composables.UseEffectCleanup
UseEffectCleanup is the cleanup function type for UseEffect.
type UseFormReturn ¶
type UseFormReturn[T any] = composables.UseFormReturn[T]
UseFormReturn is the return type for UseForm.
type UseStateReturn ¶
type UseStateReturn[T any] = composables.UseStateReturn[T]
UseStateReturn is the return type for UseState.
func UseLocalStorage ¶
func UseLocalStorage[T any](ctx *bubbly.Context, key string, initial T, storage Storage) UseStateReturn[T]
UseLocalStorage provides persistent storage integration.
type WindowSizeReturn ¶
type WindowSizeReturn = composables.WindowSizeReturn
WindowSizeReturn is the return type for UseWindowSize.