Documentation
¶
Index ¶
- func Handler(manager *Manager) http.HandlerFunc
- func Mount(component Component) (id string, html string, state map[string]any)
- func MountAndRender(w http.ResponseWriter, component Component)
- func RegisterRoutes(router *routing.Router)
- type Action
- type BaseComponent
- func (b *BaseComponent) GetID() string
- func (b *BaseComponent) GetState() map[string]any
- func (b *BaseComponent) Hydrate(data map[string]any)
- func (b *BaseComponent) MarkDirty(field string)
- func (b *BaseComponent) Mount()
- func (b *BaseComponent) Rendering()
- func (b *BaseComponent) SetID(id string)
- func (b *BaseComponent) Updated(property string)
- type Component
- type Manager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(manager *Manager) http.HandlerFunc
Handler returns an http.HandlerFunc that processes Livewire update requests. It validates the CSRF token from the X-CSRF-TOKEN header before processing.
func MountAndRender ¶
func MountAndRender(w http.ResponseWriter, component Component)
MountAndRender is a helper to mount a component and return the initial payload (useful for server-side rendering the first time).
func RegisterRoutes ¶
RegisterRoutes registers the standard Livewire endpoints. Usage in your routes file:
router := routing.NewRouter() livewire.RegisterRoutes(router)
Types ¶
type BaseComponent ¶
type BaseComponent struct {
ID string
Dirty map[string]bool
// contains filtered or unexported fields
}
BaseComponent should be embedded in your Livewire components.
func (*BaseComponent) GetID ¶
func (b *BaseComponent) GetID() string
GetID returns the component's unique ID.
func (*BaseComponent) GetState ¶
func (b *BaseComponent) GetState() map[string]any
GetState returns all exported fields as a map (for sending to frontend).
func (*BaseComponent) Hydrate ¶
func (b *BaseComponent) Hydrate(data map[string]any)
Hydrate sets the component's state from a map (used when receiving updates from frontend).
func (*BaseComponent) MarkDirty ¶
func (b *BaseComponent) MarkDirty(field string)
MarkDirty marks a property as changed.
func (*BaseComponent) Mount ¶
func (b *BaseComponent) Mount()
Lifecycle methods (no-op defaults so embedding structs satisfy the interface)
func (*BaseComponent) Rendering ¶
func (b *BaseComponent) Rendering()
func (*BaseComponent) SetID ¶
func (b *BaseComponent) SetID(id string)
SetID sets the component ID (used internally).
func (*BaseComponent) Updated ¶
func (b *BaseComponent) Updated(property string)
type Component ¶
type Component interface {
Render() string
GetID() string
SetID(id string)
GetState() map[string]any
Hydrate(data map[string]any)
MarkDirty(field string)
// Lifecycle hooks (optional)
Mount() // Called when component is first created
Updated(property string) // Called after a property is updated
Rendering() // Called before Render()
}
Component is the interface all Livewire components must implement.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles all Livewire components.
func (*Manager) RenderComponent ¶
func (m *Manager) RenderComponent(w http.ResponseWriter, component Component)
RenderComponent is a helper to render a component for the first time.