Documentation
¶
Overview ¶
Package component provides island architecture support for GoSPA. Islands are independently hydratable components with their own state.
Package component provides lifecycle management for components. Lifecycle hooks allow components to react to mount, update, and destroy events.
Package component provides priority-based hydration for GoSPA islands. This enables intelligent loading order based on component importance.
Package component provides reactive boundary detection for GoSPA.
Index ¶
- func DestroyComponent(c Component)
- func GetIslandsByPriority() map[IslandPriority][]*Island
- func MountComponent(c Component)
- func RegisterIsland(config IslandConfig) error
- func RegisterPriorityIsland(island *PriorityIsland)
- func UpdateComponent(c Component)
- type BaseComponent
- func (c *BaseComponent) AddChild(child Component)
- func (c *BaseComponent) Children() []Component
- func (c *BaseComponent) Clone() Component
- func (c *BaseComponent) Context() context.Context
- func (c *BaseComponent) GetSlot(name string) Slot
- func (c *BaseComponent) ID() ComponentID
- func (c *BaseComponent) Name() ComponentName
- func (c *BaseComponent) Parent() Component
- func (c *BaseComponent) Props() Props
- func (c *BaseComponent) RemoveChild(id ComponentID)
- func (c *BaseComponent) SetContext(ctx context.Context)
- func (c *BaseComponent) SetSlot(name string, slot Slot)
- func (c *BaseComponent) State() *state.StateMap
- func (c *BaseComponent) ToJSON() (string, error)
- type BindableProp
- func (p *BindableProp) Bind() (get func() interface{}, set func(interface{}) bool)
- func (p *BindableProp) Get() interface{}
- func (p *BindableProp) Name() string
- func (p *BindableProp) OnChange(fn func(interface{}))
- func (p *BindableProp) Set(value interface{}) bool
- func (p *BindableProp) SetValidator(fn func(interface{}) bool)
- type BindableProps
- type BoundaryType
- type CircularDependencyError
- type CleanupHook
- type Component
- type ComponentAnalysis
- type ComponentID
- type ComponentName
- type ComponentTree
- func (t *ComponentTree) Add(parentID ComponentID, child Component) error
- func (t *ComponentTree) Find(predicate func(Component) bool) Component
- func (t *ComponentTree) FindAll(predicate func(Component) bool) []Component
- func (t *ComponentTree) FindByName(name ComponentName) []Component
- func (t *ComponentTree) FindByProp(key string, value interface{}) []Component
- func (t *ComponentTree) Get(id ComponentID) Component
- func (t *ComponentTree) Mount(id ComponentID)
- func (t *ComponentTree) OnDestroy(id ComponentID, hook LifecycleHook)
- func (t *ComponentTree) OnMount(id ComponentID, hook LifecycleHook)
- func (t *ComponentTree) OnUpdate(id ComponentID, hook LifecycleHook)
- func (t *ComponentTree) Remove(id ComponentID) error
- func (t *ComponentTree) Root() Component
- func (t *ComponentTree) ToJSON() (string, error)
- func (t *ComponentTree) Update(id ComponentID)
- func (t *ComponentTree) Walk(fn func(Component) bool)
- type DetectionResult
- type Hook
- type HydrationPlan
- type HydrationStrategy
- type Island
- type IslandConfig
- type IslandData
- type IslandHydrationMode
- type IslandPriority
- type IslandRegistry
- func (r *IslandRegistry) Create(name string, props map[string]any) (*Island, error)
- func (r *IslandRegistry) Get(id string) (*Island, bool)
- func (r *IslandRegistry) GetAll() []*Island
- func (r *IslandRegistry) GetByPriority() map[IslandPriority][]*Island
- func (r *IslandRegistry) Register(config IslandConfig) error
- func (r *IslandRegistry) Remove(id string)
- func (r *IslandRegistry) SerializeState() (map[string]map[string]any, error)
- type Lifecycle
- func (l *Lifecycle) ClearHooks()
- func (l *Lifecycle) Destroy()
- func (l *Lifecycle) IsMounted() bool
- func (l *Lifecycle) Mount()
- func (l *Lifecycle) OnBeforeDestroy(hook Hook)
- func (l *Lifecycle) OnBeforeMount(hook Hook)
- func (l *Lifecycle) OnBeforeUpdate(hook Hook)
- func (l *Lifecycle) OnCleanup(hook CleanupHook)
- func (l *Lifecycle) OnDestroy(hook Hook)
- func (l *Lifecycle) OnMount(hook Hook)
- func (l *Lifecycle) OnUpdate(hook Hook)
- func (l *Lifecycle) Phase() LifecyclePhase
- func (l *Lifecycle) Update()
- type LifecycleAware
- type LifecycleHook
- type LifecyclePhase
- type Option
- type PriorityConfig
- type PriorityIsland
- type PriorityLevel
- type PriorityQueue
- func (pq *PriorityQueue) Clear()
- func (pq *PriorityQueue) Count() int
- func (pq *PriorityQueue) CreatePlan() *HydrationPlan
- func (pq *PriorityQueue) GetByMinPriority(minPriority PriorityLevel) []*PriorityIsland
- func (pq *PriorityQueue) GetByMode(mode IslandHydrationMode) []*PriorityIsland
- func (pq *PriorityQueue) GetConfig() PriorityConfig
- func (pq *PriorityQueue) GetCritical() []*PriorityIsland
- func (pq *PriorityQueue) GetDependencyOrder() ([]*PriorityIsland, error)
- func (pq *PriorityQueue) GetOrdered() []*PriorityIsland
- func (pq *PriorityQueue) Register(island *PriorityIsland)
- func (pq *PriorityQueue) RegisterBatch(islands []*PriorityIsland)
- type PropDefinition
- type PropSchema
- func (s *PropSchema) ApplyDefaults(props Props) Props
- func (s *PropSchema) Define(name string, kind reflect.Kind, defaultValue interface{}, required bool) *PropSchema
- func (s *PropSchema) DefineWithValidator(name string, kind reflect.Kind, defaultValue interface{}, required bool, ...) *PropSchema
- func (s *PropSchema) Definitions() map[string]PropDefinition
- func (s *PropSchema) GetDefinition(name string) (PropDefinition, bool)
- func (s *PropSchema) Validate(props Props) error
- func (s *PropSchema) ValidateAndApply(props Props) (Props, error)
- type Props
- func (p Props) Clone() Props
- func (p Props) Delete(key string)
- func (p Props) Equals(other Props) bool
- func (p Props) Get(key string) interface{}
- func (p Props) GetBool(key string) bool
- func (p Props) GetDefault(key string, defaultValue interface{}) interface{}
- func (p Props) GetFloat64(key string) float64
- func (p Props) GetInt(key string) int
- func (p Props) GetInt64(key string) int64
- func (p Props) GetMap(key string) map[string]interface{}
- func (p Props) GetSlice(key string) []interface{}
- func (p Props) GetString(key string) string
- func (p Props) Has(key string) bool
- func (p Props) Keys() []string
- func (p Props) Merge(other Props)
- func (p Props) Set(key string, value interface{})
- func (p Props) ToJSON() (string, error)
- func (p Props) Values() []interface{}
- type ReactiveBoundary
- type ReactiveDetector
- type Slot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DestroyComponent ¶
func DestroyComponent(c Component)
DestroyComponent destroys a component and its children
func GetIslandsByPriority ¶
func GetIslandsByPriority() map[IslandPriority][]*Island
GetIslandsByPriority returns islands grouped by priority.
func MountComponent ¶
func MountComponent(c Component)
MountComponent mounts a component and its children
func RegisterIsland ¶
func RegisterIsland(config IslandConfig) error
RegisterIsland registers an island configuration globally.
func RegisterPriorityIsland ¶
func RegisterPriorityIsland(island *PriorityIsland)
RegisterPriorityIsland registers an island in the global priority queue.
Types ¶
type BaseComponent ¶
type BaseComponent struct {
// contains filtered or unexported fields
}
BaseComponent is the base implementation of a component.
func NewBaseComponent ¶
func NewBaseComponent(id ComponentID, name ComponentName, opts ...Option) *BaseComponent
NewBaseComponent creates a new base component.
func (*BaseComponent) AddChild ¶
func (c *BaseComponent) AddChild(child Component)
AddChild adds a child component.
func (*BaseComponent) Children ¶
func (c *BaseComponent) Children() []Component
Children returns the component's children.
func (*BaseComponent) Clone ¶
func (c *BaseComponent) Clone() Component
Clone creates a copy of the component.
func (*BaseComponent) Context ¶
func (c *BaseComponent) Context() context.Context
Context returns the component's context.
func (*BaseComponent) GetSlot ¶
func (c *BaseComponent) GetSlot(name string) Slot
GetSlot returns a slot by name.
func (*BaseComponent) ID ¶
func (c *BaseComponent) ID() ComponentID
ID returns the component's unique identifier.
func (*BaseComponent) Name ¶
func (c *BaseComponent) Name() ComponentName
Name returns the component's name.
func (*BaseComponent) Parent ¶
func (c *BaseComponent) Parent() Component
Parent returns the component's parent.
func (*BaseComponent) Props ¶
func (c *BaseComponent) Props() Props
Props returns the component's props.
func (*BaseComponent) RemoveChild ¶
func (c *BaseComponent) RemoveChild(id ComponentID)
RemoveChild removes a child component.
func (*BaseComponent) SetContext ¶
func (c *BaseComponent) SetContext(ctx context.Context)
SetContext sets the component's context.
func (*BaseComponent) SetSlot ¶
func (c *BaseComponent) SetSlot(name string, slot Slot)
SetSlot sets a slot.
func (*BaseComponent) State ¶
func (c *BaseComponent) State() *state.StateMap
State returns the component's state.
func (*BaseComponent) ToJSON ¶
func (c *BaseComponent) ToJSON() (string, error)
ToJSON returns the component's state as JSON.
type BindableProp ¶
type BindableProp struct {
// contains filtered or unexported fields
}
BindableProp is a prop that can be bound two-way.
func NewBindableProp ¶
func NewBindableProp(name string, initialValue interface{}) *BindableProp
NewBindableProp creates a new bindable prop.
func (*BindableProp) Bind ¶
func (p *BindableProp) Bind() (get func() interface{}, set func(interface{}) bool)
Bind creates a two-way binding.
func (*BindableProp) OnChange ¶
func (p *BindableProp) OnChange(fn func(interface{}))
OnChange sets the change callback.
func (*BindableProp) Set ¶
func (p *BindableProp) Set(value interface{}) bool
Set sets a new value and triggers onChange.
func (*BindableProp) SetValidator ¶
func (p *BindableProp) SetValidator(fn func(interface{}) bool)
SetValidator sets the validator.
type BindableProps ¶
type BindableProps struct {
// contains filtered or unexported fields
}
BindableProps is a collection of bindable props.
func NewBindableProps ¶
func NewBindableProps() *BindableProps
NewBindableProps creates a new bindable props collection.
func (*BindableProps) Add ¶
func (bp *BindableProps) Add(name string, initialValue interface{}) *BindableProp
Add adds a bindable prop.
func (*BindableProps) Get ¶
func (bp *BindableProps) Get(name string) *BindableProp
Get returns a bindable prop by name.
func (*BindableProps) Names ¶
func (bp *BindableProps) Names() []string
Names returns all prop names.
func (*BindableProps) Remove ¶
func (bp *BindableProps) Remove(name string)
Remove removes a bindable prop.
func (*BindableProps) ToProps ¶
func (bp *BindableProps) ToProps() Props
ToProps converts to regular Props.
type BoundaryType ¶
type BoundaryType string
BoundaryType represents the type of reactive boundary.
const ( BoundaryTypeState BoundaryType = "state" BoundaryTypeDerived BoundaryType = "derived" BoundaryTypeEffect BoundaryType = "effect" BoundaryTypeComponent BoundaryType = "component" BoundaryTypeEvent BoundaryType = "event" BoundaryTypeComputed BoundaryType = "computed" )
type CircularDependencyError ¶
type CircularDependencyError struct {
ID string
}
CircularDependencyError indicates a circular dependency was detected.
func (*CircularDependencyError) Error ¶
func (e *CircularDependencyError) Error() string
type Component ¶
type Component interface {
// ID returns the component's unique identifier.
ID() ComponentID
// Name returns the component's name.
Name() ComponentName
// State returns the component's state.
State() *state.StateMap
// Props returns the component's props.
Props() Props
// Children returns the component's children.
Children() []Component
// Parent returns the component's parent.
Parent() Component
// AddChild adds a child component.
AddChild(child Component)
// RemoveChild removes a child component.
RemoveChild(id ComponentID)
// GetSlot returns a slot by name.
GetSlot(name string) Slot
// SetSlot sets a slot.
SetSlot(name string, slot Slot)
// Context returns the component's context.
Context() context.Context
// SetContext sets the component's context.
SetContext(ctx context.Context)
// ToJSON returns the component's state as JSON.
ToJSON() (string, error)
// Clone creates a copy of the component.
Clone() Component
}
Component is the interface for a component.
type ComponentAnalysis ¶
type ComponentAnalysis struct {
ComponentName string `json:"componentName"`
FilePath string `json:"filePath"`
Boundaries []ReactiveBoundary `json:"boundaries"`
IsReactive bool `json:"isReactive"`
ShouldIsland bool `json:"shouldIsland"`
HydrationStrategy HydrationStrategy `json:"hydrationStrategy"`
}
ComponentAnalysis contains detailed analysis of a component.
func AnalyzeComponentFile ¶
func AnalyzeComponentFile(source, filePath, componentName string) *ComponentAnalysis
AnalyzeComponentFile analyzes a component file using the global detector.
type ComponentTree ¶
type ComponentTree struct {
// contains filtered or unexported fields
}
ComponentTree represents a tree of components.
func NewComponentTree ¶
func NewComponentTree(root Component) *ComponentTree
NewComponentTree creates a new component tree.
func (*ComponentTree) Add ¶
func (t *ComponentTree) Add(parentID ComponentID, child Component) error
Add adds a component to the tree.
func (*ComponentTree) Find ¶
func (t *ComponentTree) Find(predicate func(Component) bool) Component
Find finds a component by predicate.
func (*ComponentTree) FindAll ¶
func (t *ComponentTree) FindAll(predicate func(Component) bool) []Component
FindAll finds all components matching a predicate.
func (*ComponentTree) FindByName ¶
func (t *ComponentTree) FindByName(name ComponentName) []Component
FindByName finds components by name.
func (*ComponentTree) FindByProp ¶
func (t *ComponentTree) FindByProp(key string, value interface{}) []Component
FindByProp finds components by prop value.
func (*ComponentTree) Get ¶
func (t *ComponentTree) Get(id ComponentID) Component
Get returns a component by ID.
func (*ComponentTree) Mount ¶
func (t *ComponentTree) Mount(id ComponentID)
Mount calls the mount hook for a component.
func (*ComponentTree) OnDestroy ¶
func (t *ComponentTree) OnDestroy(id ComponentID, hook LifecycleHook)
OnDestroy registers a destroy hook for a component.
func (*ComponentTree) OnMount ¶
func (t *ComponentTree) OnMount(id ComponentID, hook LifecycleHook)
OnMount registers a mount hook for a component.
func (*ComponentTree) OnUpdate ¶
func (t *ComponentTree) OnUpdate(id ComponentID, hook LifecycleHook)
OnUpdate registers an update hook for a component.
func (*ComponentTree) Remove ¶
func (t *ComponentTree) Remove(id ComponentID) error
Remove removes a component from the tree.
func (*ComponentTree) Root ¶
func (t *ComponentTree) Root() Component
Root returns the root component.
func (*ComponentTree) ToJSON ¶
func (t *ComponentTree) ToJSON() (string, error)
ToJSON returns the entire tree's state as JSON.
func (*ComponentTree) Update ¶
func (t *ComponentTree) Update(id ComponentID)
Update calls the update hook for a component.
func (*ComponentTree) Walk ¶
func (t *ComponentTree) Walk(fn func(Component) bool)
Walk walks the component tree.
type DetectionResult ¶
type DetectionResult struct {
Boundaries []ReactiveBoundary `json:"boundaries"`
StateCount int `json:"stateCount"`
DerivedCount int `json:"derivedCount"`
EffectCount int `json:"effectCount"`
IslandCount int `json:"islandCount"`
ComponentName string `json:"componentName"`
FilePath string `json:"filePath"`
}
DetectionResult contains the results of reactive boundary detection.
func DetectReactiveBoundaries ¶
func DetectReactiveBoundaries(source, filePath string) *DetectionResult
DetectReactiveBoundaries is a convenience function using the global detector.
type HydrationPlan ¶
type HydrationPlan struct {
// Immediate islands to hydrate right away.
Immediate []*PriorityIsland `json:"immediate"`
// Idle islands to hydrate during idle time.
Idle []*PriorityIsland `json:"idle"`
// Visible islands to hydrate on viewport entry.
Visible []*PriorityIsland `json:"visible"`
// Interaction islands to hydrate on user interaction.
Interaction []*PriorityIsland `json:"interaction"`
// Lazy islands to hydrate when resources permit.
Lazy []*PriorityIsland `json:"lazy"`
// Preload scripts for high-priority islands.
Preload []string `json:"preload"`
}
HydrationPlan represents a complete hydration schedule.
func CreateHydrationPlan ¶
func CreateHydrationPlan() *HydrationPlan
CreateHydrationPlan creates a hydration plan from the global queue.
type HydrationStrategy ¶
type HydrationStrategy struct {
Mode IslandHydrationMode `json:"mode"`
Priority IslandPriority `json:"priority"`
Reason string `json:"reason"`
Dependencies []string `json:"dependencies"`
CriticalPath bool `json:"criticalPath"`
}
HydrationStrategy represents the recommended hydration strategy.
type Island ¶
type Island struct {
ID string
Config IslandConfig
Props map[string]any
State map[string]any
Children string // HTML content from SSR
}
Island represents a registered island component.
func CreateIsland ¶
CreateIsland creates a new island instance in the global registry.
func GetAllIslands ¶
func GetAllIslands() []*Island
GetAllIslands returns all islands from the global registry.
func (*Island) ToData ¶
func (i *Island) ToData() IslandData
ToData converts an island to client-transferable data.
type IslandConfig ¶
type IslandConfig struct {
// Name is the unique identifier for this island type.
Name string
// HydrationMode determines when the island hydrates.
HydrationMode IslandHydrationMode
// Priority affects loading order.
Priority IslandPriority
// ClientOnly skips SSR entirely.
ClientOnly bool
// ServerOnly renders HTML without client JS.
ServerOnly bool
// LazyThreshold for visible mode - margin in pixels.
LazyThreshold int
// DeferDelay for idle mode - max delay in ms.
DeferDelay int
}
IslandConfig configures an island's behavior.
type IslandData ¶
type IslandData struct {
ID string `json:"id"`
Name string `json:"name"`
Props map[string]any `json:"props,omitempty"`
State map[string]any `json:"state,omitempty"`
HTML string `json:"html,omitempty"`
Mode string `json:"mode"`
Priority string `json:"priority"`
}
IslandData is the data structure sent to the client.
type IslandHydrationMode ¶
type IslandHydrationMode string
IslandHydrationMode defines when an island should hydrate.
const ( // HydrationImmediate hydrates as soon as the script loads. HydrationImmediate IslandHydrationMode = "immediate" // HydrationVisible hydrates when the island enters the viewport. HydrationVisible IslandHydrationMode = "visible" // HydrationIdle hydrates during browser idle time. HydrationIdle IslandHydrationMode = "idle" // HydrationInteraction hydrates on first user interaction. HydrationInteraction IslandHydrationMode = "interaction" // HydrationLazy hydrates when explicitly triggered. HydrationLazy IslandHydrationMode = "lazy" )
type IslandPriority ¶
type IslandPriority string
IslandPriority defines the loading priority for an island.
const ( // PriorityHigh for above-fold critical content. PriorityHigh IslandPriority = "high" // PriorityNormal for standard content. PriorityNormal IslandPriority = "normal" // PriorityLow for below-fold or deferred content. PriorityLow IslandPriority = "low" )
func IslandPriorityFromLevel ¶
func IslandPriorityFromLevel(p PriorityLevel) IslandPriority
IslandPriorityFromLevel converts PriorityLevel to IslandPriority.
type IslandRegistry ¶
type IslandRegistry struct {
// contains filtered or unexported fields
}
IslandRegistry manages all registered islands.
func NewIslandRegistry ¶
func NewIslandRegistry() *IslandRegistry
NewIslandRegistry creates a new island registry.
func (*IslandRegistry) Get ¶
func (r *IslandRegistry) Get(id string) (*Island, bool)
Get retrieves an island by ID.
func (*IslandRegistry) GetAll ¶
func (r *IslandRegistry) GetAll() []*Island
GetAll returns all active islands.
func (*IslandRegistry) GetByPriority ¶
func (r *IslandRegistry) GetByPriority() map[IslandPriority][]*Island
GetByPriority returns islands grouped by priority.
func (*IslandRegistry) Register ¶
func (r *IslandRegistry) Register(config IslandConfig) error
Register registers an island configuration.
func (*IslandRegistry) Remove ¶
func (r *IslandRegistry) Remove(id string)
Remove removes an island from the registry.
func (*IslandRegistry) SerializeState ¶
func (r *IslandRegistry) SerializeState() (map[string]map[string]any, error)
SerializeState returns the serialized state for all islands.
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle manages component lifecycle hooks and state
func (*Lifecycle) OnBeforeDestroy ¶
OnBeforeDestroy registers a hook to run before destroying
func (*Lifecycle) OnBeforeMount ¶
OnBeforeMount registers a hook to run before mounting
func (*Lifecycle) OnBeforeUpdate ¶
OnBeforeUpdate registers a hook to run before updating
func (*Lifecycle) OnCleanup ¶
func (l *Lifecycle) OnCleanup(hook CleanupHook)
OnCleanup registers a cleanup hook to run on destroy
func (*Lifecycle) Phase ¶
func (l *Lifecycle) Phase() LifecyclePhase
Phase returns the current lifecycle phase
type LifecycleAware ¶
type LifecycleAware interface {
// Lifecycle returns the lifecycle manager
Lifecycle() *Lifecycle
}
LifecycleAware is an interface for components with lifecycle
type LifecycleHook ¶
type LifecycleHook func(Component)
LifecycleHook is a function called during component lifecycle.
type LifecyclePhase ¶
type LifecyclePhase int
LifecyclePhase represents the current phase of a component's lifecycle
const ( // PhaseCreated is the initial state after component creation PhaseCreated LifecyclePhase = iota // PhaseMounting is when the component is being mounted PhaseMounting // PhaseMounted is when the component is fully mounted PhaseMounted // PhaseUpdating is when the component is updating PhaseUpdating // PhaseUpdated is when the component has finished updating PhaseUpdated // PhaseDestroying is when the component is being destroyed PhaseDestroying // PhaseDestroyed is when the component is fully destroyed PhaseDestroyed )
func (LifecyclePhase) String ¶
func (p LifecyclePhase) String() string
String returns the string representation of the lifecycle phase
type Option ¶
type Option func(*BaseComponent)
Option is a functional option for creating components.
func WithChildren ¶
WithChildren sets the component's children.
func WithContext ¶
WithContext sets the component's context.
type PriorityConfig ¶
type PriorityConfig struct {
// MaxConcurrent limits simultaneous hydrations.
MaxConcurrent int `json:"maxConcurrent"`
// IdleTimeout is the deadline for idle callbacks (ms).
IdleTimeout int `json:"idleTimeout"`
// IntersectionThreshold for visible strategy (0-1).
IntersectionThreshold float64 `json:"intersectionThreshold"`
// IntersectionRootMargin for visible strategy.
IntersectionRootMargin string `json:"intersectionRootMargin"`
// EnablePreload enables preloading of island scripts.
EnablePreload bool `json:"enablePreload"`
}
PriorityConfig configures priority-based hydration behavior.
func DefaultPriorityConfig ¶
func DefaultPriorityConfig() PriorityConfig
DefaultPriorityConfig returns sensible defaults.
type PriorityIsland ¶
type PriorityIsland struct {
ID string `json:"id"`
Name string `json:"name"`
Priority PriorityLevel `json:"priority"`
Mode IslandHydrationMode `json:"mode"`
Dependencies []string `json:"dependencies,omitempty"`
State json.RawMessage `json:"state,omitempty"`
Script string `json:"script,omitempty"`
Position int `json:"position"`
Metadata map[string]any `json:"metadata,omitempty"`
}
PriorityIsland represents an island with extended priority information.
func PriorityIslandFromIsland ¶
func PriorityIslandFromIsland(island *Island, position int) *PriorityIsland
PriorityIslandFromIsland converts an Island to a PriorityIsland.
type PriorityLevel ¶
type PriorityLevel int
PriorityLevel is a numeric priority for hydration ordering. Higher values hydrate first.
const ( // PriorityLevelCritical - Above the fold, immediately visible, interactive. PriorityLevelCritical PriorityLevel = 100 // PriorityLevelHigh - Important UI elements, likely to be interacted with. PriorityLevelHigh PriorityLevel = 75 // PriorityLevelNormal - Standard content, below the fold. PriorityLevelNormal PriorityLevel = 50 // PriorityLevelLow - Non-essential content, ads, recommendations. PriorityLevelLow PriorityLevel = 25 // PriorityLevelDeferred - Extremely low priority, may never hydrate. PriorityLevelDeferred PriorityLevel = 10 )
func PriorityFromIslandPriority ¶
func PriorityFromIslandPriority(p IslandPriority) PriorityLevel
PriorityFromIslandPriority converts IslandPriority to PriorityLevel.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue manages islands ordered by priority.
func GetPriorityQueue ¶
func GetPriorityQueue() *PriorityQueue
GetPriorityQueue returns the global priority queue.
func NewPriorityQueue ¶
func NewPriorityQueue(config PriorityConfig) *PriorityQueue
NewPriorityQueue creates a new priority queue.
func (*PriorityQueue) Clear ¶
func (pq *PriorityQueue) Clear()
Clear removes all islands from the queue.
func (*PriorityQueue) Count ¶
func (pq *PriorityQueue) Count() int
Count returns the number of islands in the queue.
func (*PriorityQueue) CreatePlan ¶
func (pq *PriorityQueue) CreatePlan() *HydrationPlan
CreatePlan generates a hydration plan from the queue.
func (*PriorityQueue) GetByMinPriority ¶
func (pq *PriorityQueue) GetByMinPriority(minPriority PriorityLevel) []*PriorityIsland
GetByMinPriority returns islands at or above the given priority.
func (*PriorityQueue) GetByMode ¶
func (pq *PriorityQueue) GetByMode(mode IslandHydrationMode) []*PriorityIsland
GetByMode returns islands filtered by hydration mode.
func (*PriorityQueue) GetConfig ¶
func (pq *PriorityQueue) GetConfig() PriorityConfig
GetConfig returns the current configuration.
func (*PriorityQueue) GetCritical ¶
func (pq *PriorityQueue) GetCritical() []*PriorityIsland
GetCritical returns all critical priority islands.
func (*PriorityQueue) GetDependencyOrder ¶
func (pq *PriorityQueue) GetDependencyOrder() ([]*PriorityIsland, error)
GetDependencyOrder returns islands in dependency-resolved order.
func (*PriorityQueue) GetOrdered ¶
func (pq *PriorityQueue) GetOrdered() []*PriorityIsland
GetOrdered returns islands sorted by priority (highest first).
func (*PriorityQueue) Register ¶
func (pq *PriorityQueue) Register(island *PriorityIsland)
Register adds an island to the priority queue.
func (*PriorityQueue) RegisterBatch ¶
func (pq *PriorityQueue) RegisterBatch(islands []*PriorityIsland)
RegisterBatch adds multiple islands at once.
type PropDefinition ¶
type PropDefinition struct {
Name string
Type reflect.Kind
DefaultValue interface{}
Required bool
Validator func(interface{}) bool
}
PropDefinition defines a prop's type and default value.
type PropSchema ¶
type PropSchema struct {
// contains filtered or unexported fields
}
PropSchema defines the schema for component props.
func (*PropSchema) ApplyDefaults ¶
func (s *PropSchema) ApplyDefaults(props Props) Props
ApplyDefaults applies default values to props.
func (*PropSchema) Define ¶
func (s *PropSchema) Define(name string, kind reflect.Kind, defaultValue interface{}, required bool) *PropSchema
Define defines a prop.
func (*PropSchema) DefineWithValidator ¶
func (s *PropSchema) DefineWithValidator(name string, kind reflect.Kind, defaultValue interface{}, required bool, validator func(interface{}) bool) *PropSchema
DefineWithValidator defines a prop with a validator.
func (*PropSchema) Definitions ¶
func (s *PropSchema) Definitions() map[string]PropDefinition
Definitions returns all prop definitions.
func (*PropSchema) GetDefinition ¶
func (s *PropSchema) GetDefinition(name string) (PropDefinition, bool)
GetDefinition returns a prop definition.
func (*PropSchema) Validate ¶
func (s *PropSchema) Validate(props Props) error
Validate validates props against the schema.
func (*PropSchema) ValidateAndApply ¶
func (s *PropSchema) ValidateAndApply(props Props) (Props, error)
ValidateAndApply validates props and applies defaults.
type Props ¶
type Props map[string]interface{}
Props is a map of component properties.
func PropsFromJSON ¶
FromJSON creates Props from JSON.
func (Props) GetDefault ¶
GetDefault returns a prop value with a default.
func (Props) GetFloat64 ¶
GetFloat64 returns a prop as a float64.
type ReactiveBoundary ¶
type ReactiveBoundary struct {
Name string `json:"name"`
Type BoundaryType `json:"type"`
LineNumber int `json:"lineNumber"`
Dependencies []string `json:"dependencies"`
StateVars []string `json:"stateVars"`
Props []string `json:"props"`
IsIsland bool `json:"isIsland"`
HydrationMode IslandHydrationMode `json:"hydrationMode,omitempty"`
Priority IslandPriority `json:"priority,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ReactiveBoundary represents a detected reactive boundary in a component.
type ReactiveDetector ¶
type ReactiveDetector struct {
// contains filtered or unexported fields
}
ReactiveDetector detects reactive boundaries in templ components.
func NewReactiveDetector ¶
func NewReactiveDetector() *ReactiveDetector
NewReactiveDetector creates a new reactive boundary detector.
func (*ReactiveDetector) AnalyzeComponent ¶
func (rd *ReactiveDetector) AnalyzeComponent(source, filePath, componentName string) *ComponentAnalysis
AnalyzeComponent analyzes a component file for reactive boundaries.
func (*ReactiveDetector) Detect ¶
func (rd *ReactiveDetector) Detect(source, filePath string) *DetectionResult
Detect analyzes source code and returns detected reactive boundaries.