livewire

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 Mount

func Mount(component Component) (id string, html string, state map[string]any)

Mount is a convenience helper to create and render a component in one call.

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

func RegisterRoutes(router *routing.Router)

RegisterRoutes registers the standard Livewire endpoints. Usage in your routes file:

router := routing.NewRouter()
livewire.RegisterRoutes(router)

Types

type Action

type Action struct {
	Name   string
	Params []any
}

Action represents a method call from the frontend.

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 NewManager

func NewManager() *Manager

NewManager creates a new Livewire manager.

func (*Manager) Get

func (m *Manager) Get(id string) (Component, bool)

Get retrieves a component by ID.

func (*Manager) Register

func (m *Manager) Register(component Component) string

Register creates a new instance of a component and returns its ID.

func (*Manager) Remove

func (m *Manager) Remove(id string)

Remove deletes a component.

func (*Manager) RenderComponent

func (m *Manager) RenderComponent(w http.ResponseWriter, component Component)

RenderComponent is a helper to render a component for the first time.

func (*Manager) Update

func (m *Manager) Update(w http.ResponseWriter, r *http.Request)

Update handles an incoming Livewire update request from the frontend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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