Documentation
¶
Overview ¶
Package composables provides reusable reactive logic for the profiler example.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats bytes into a human-readable string.
func FormatDuration ¶
FormatDuration formats a duration into a human-readable string.
Types ¶
type ProfilerComposable ¶
type ProfilerComposable struct {
// Profiler is the underlying profiler instance
Profiler *profiler.Profiler
// IsRunning indicates if profiling is active
IsRunning *bubbly.Ref[bool]
// Metrics holds the current profiler metrics
Metrics *bubbly.Ref[*ProfilerMetrics]
// StartTime is when profiling started
StartTime *bubbly.Ref[time.Time]
// Duration is computed from StartTime
Duration *bubbly.Computed[interface{}]
// LastExport holds the last export filename (empty if none)
LastExport *bubbly.Ref[string]
// Start begins profiling
Start func()
// Stop ends profiling
Stop func()
// Toggle switches profiling state
Toggle func()
// Reset clears all metrics
Reset func()
// ExportReport saves the report to a file
ExportReport func(filename string) error
// RefreshMetrics updates the metrics from the profiler
RefreshMetrics func()
// contains filtered or unexported fields
}
ProfilerComposable encapsulates profiler logic with reactive state. This follows the Vue-like composable pattern for reusable logic.
func UseProfiler ¶
func UseProfiler(ctx *bubbly.Context) *ProfilerComposable
UseProfiler creates a reusable profiler composable with reactive state. This demonstrates the composable pattern - reusable logic that can be shared across components, similar to Vue's Composition API.
Example:
profilerComp := composables.UseProfiler(ctx) profilerComp.Start() // ... later profilerComp.RefreshMetrics() metrics := profilerComp.Metrics.GetTyped()
Click to show internal directories.
Click to hide internal directories.