component

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

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.

func UpdateComponent

func UpdateComponent(c Component)

UpdateComponent updates a component

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) Get

func (p *BindableProp) Get() interface{}

Get returns the current value.

func (*BindableProp) Name

func (p *BindableProp) Name() string

Name returns the prop name.

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 CleanupHook

type CleanupHook func()

CleanupHook is a function that runs during cleanup

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 ComponentID

type ComponentID string

ComponentID is a unique identifier for a component.

type ComponentName

type ComponentName string

ComponentName is the name of a component.

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 Hook

type Hook func()

Hook is a function that runs during a lifecycle phase

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

func CreateIsland(name string, props map[string]any) (*Island, error)

CreateIsland creates a new island instance in the global registry.

func GetAllIslands

func GetAllIslands() []*Island

GetAllIslands returns all islands from the global registry.

func GetIsland

func GetIsland(id string) (*Island, bool)

GetIsland retrieves an island from the global registry.

func (*Island) ToData

func (i *Island) ToData() IslandData

ToData converts an island to client-transferable data.

func (*Island) ToJSON

func (i *Island) ToJSON() ([]byte, error)

ToJSON serializes island data to JSON.

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) Create

func (r *IslandRegistry) Create(name string, props map[string]any) (*Island, error)

Create creates a new island instance.

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 NewLifecycle

func NewLifecycle() *Lifecycle

NewLifecycle creates a new lifecycle manager

func (*Lifecycle) ClearHooks

func (l *Lifecycle) ClearHooks()

ClearHooks removes all hooks

func (*Lifecycle) Destroy

func (l *Lifecycle) Destroy()

Destroy triggers the destroy lifecycle

func (*Lifecycle) IsMounted

func (l *Lifecycle) IsMounted() bool

IsMounted returns true if the component is mounted

func (*Lifecycle) Mount

func (l *Lifecycle) Mount()

Mount triggers the mount lifecycle

func (*Lifecycle) OnBeforeDestroy

func (l *Lifecycle) OnBeforeDestroy(hook Hook)

OnBeforeDestroy registers a hook to run before destroying

func (*Lifecycle) OnBeforeMount

func (l *Lifecycle) OnBeforeMount(hook Hook)

OnBeforeMount registers a hook to run before mounting

func (*Lifecycle) OnBeforeUpdate

func (l *Lifecycle) OnBeforeUpdate(hook Hook)

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) OnDestroy

func (l *Lifecycle) OnDestroy(hook Hook)

OnDestroy registers a hook to run after destroying

func (*Lifecycle) OnMount

func (l *Lifecycle) OnMount(hook Hook)

OnMount registers a hook to run after mounting

func (*Lifecycle) OnUpdate

func (l *Lifecycle) OnUpdate(hook Hook)

OnUpdate registers a hook to run after updating

func (*Lifecycle) Phase

func (l *Lifecycle) Phase() LifecyclePhase

Phase returns the current lifecycle phase

func (*Lifecycle) Update

func (l *Lifecycle) Update()

Update triggers the update lifecycle

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

func WithChildren(children ...Component) Option

WithChildren sets the component's children.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the component's context.

func WithParent

func WithParent(parent Component) Option

WithParent sets the component's parent.

func WithProps

func WithProps(props Props) Option

WithProps sets the component's props.

func WithSlots

func WithSlots(slots map[string]Slot) Option

WithSlots sets the component's slots.

func WithState

func WithState(initialState map[string]interface{}) Option

WithState sets the component's initial state.

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 NewPropSchema

func NewPropSchema() *PropSchema

NewPropSchema creates a new prop schema.

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

func PropsFromJSON(data string) (Props, error)

FromJSON creates Props from JSON.

func (Props) Clone

func (p Props) Clone() Props

Clone creates a copy of the props.

func (Props) Delete

func (p Props) Delete(key string)

Delete removes a prop.

func (Props) Equals

func (p Props) Equals(other Props) bool

Equals checks if two Props are equal.

func (Props) Get

func (p Props) Get(key string) interface{}

Get returns a prop value by key.

func (Props) GetBool

func (p Props) GetBool(key string) bool

GetBool returns a prop as a bool.

func (Props) GetDefault

func (p Props) GetDefault(key string, defaultValue interface{}) interface{}

GetDefault returns a prop value with a default.

func (Props) GetFloat64

func (p Props) GetFloat64(key string) float64

GetFloat64 returns a prop as a float64.

func (Props) GetInt

func (p Props) GetInt(key string) int

GetInt returns a prop as an int.

func (Props) GetInt64

func (p Props) GetInt64(key string) int64

GetInt64 returns a prop as an int64.

func (Props) GetMap

func (p Props) GetMap(key string) map[string]interface{}

GetMap returns a prop as a map.

func (Props) GetSlice

func (p Props) GetSlice(key string) []interface{}

GetSlice returns a prop as a slice.

func (Props) GetString

func (p Props) GetString(key string) string

GetString returns a prop as a string.

func (Props) Has

func (p Props) Has(key string) bool

Has checks if a prop exists.

func (Props) Keys

func (p Props) Keys() []string

Keys returns all prop keys.

func (Props) Merge

func (p Props) Merge(other Props)

Merge merges another Props into this one.

func (Props) Set

func (p Props) Set(key string, value interface{})

Set sets a prop value.

func (Props) ToJSON

func (p Props) ToJSON() (string, error)

ToJSON returns the props as JSON.

func (Props) Values

func (p Props) Values() []interface{}

Values returns all prop values.

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.

type Slot

type Slot func() string

Slot is a function that renders content.

Directories

Path Synopsis
Package starter provides a library of reusable UI components for GoSPA applications
Package starter provides a library of reusable UI components for GoSPA applications

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL