dom

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalPatchset

func MarshalPatchset(t *template.Template, patchset []Patch) []byte

MarshalPatchset renders the patch operations to a json string

Types

type Patch

type Patch struct {
	// Type is the type of patch operation
	Type PatchType `json:"op"`
	// Selector is the css selector for the element to patch
	Selector *string `json:"selector,omitempty"`
	// Value is the value for the patch operation
	Value any `json:"value,omitempty"`
	// EventSourceID is the id of the element that triggered the event
	EventSourceID *string `json:"eid,omitempty"`
}

Patch is an interface for all patch operations

type PatchType

type PatchType string

PatchType is the type of patch operation

const (
	ReplaceElement PatchType = "replaceElement"
	ReplaceContent PatchType = "replaceContent"
	After          PatchType = "after"
	Before         PatchType = "before"
	Append         PatchType = "append"
	Prepend        PatchType = "prepend"
	Remove         PatchType = "remove"
	Reload         PatchType = "reload"
	Store          PatchType = "store"
	ResetForm      PatchType = "resetForm"
	Navigate       PatchType = "navigate"
	DispatchEvent  PatchType = "dispatchEvent"
)

type Patcher

type Patcher interface {
	// ReplaceEl patches the dom element at the given selector with the rendered template
	ReplaceEl(selector string, t TemplateRenderer) Patcher
	// ReplaceContent patches the dom element content at the given selector with the rendered template
	ReplaceContent(selector string, t TemplateRenderer) Patcher
	// After patches the dom element after the given selector with the rendered template
	AfterEl(selector string, t TemplateRenderer) Patcher
	// Before patches the dom element before the given selector with the rendered template
	BeforeEl(selector string, t TemplateRenderer) Patcher
	// Append patches the dom element  after the given selector with the rendered template
	AppendEl(selector string, t TemplateRenderer) Patcher
	// Prepend patches the dom element before the given selector with the rendered template
	PrependEl(selector string, t TemplateRenderer) Patcher
	// Remove patches the dom element to remove the given selector
	RemoveEl(selector string) Patcher
	// Reload patches the dom  to reload the page
	Reload() Patcher
	// Store patches the dom  to update the alpinejs store
	Store(name string, data any) Patcher
	// ResetForm patches the dom to reset the form
	ResetForm(selector string) Patcher
	// Navigate patches the dom to navigate to the given url
	Navigate(url string) Patcher
	// DispatchEvent patches the dom to dispatch the given event
	DispatchEvent(selector, eventSourceID string, t TemplateRenderer) Patcher
	// Patchset returns the patchset
	Patchset() Patchset
	// Error satisfies the error interface so that Context can return a Patcher
	Error() string
}

func NewPatcher

func NewPatcher() Patcher

NewPatcher creates a new dom patcher

type Patchset

type Patchset []Patch

Patchset is a collection of patch operations

type TemplateRenderer

type TemplateRenderer interface {
	Name() string
	Data() any
}

TemplateRenderer is an interface for rendering partial templates

func NewTemplateRenderer

func NewTemplateRenderer(name string, data any) TemplateRenderer

NewTemplateRenderer creates a new template renderer

Jump to

Keyboard shortcuts

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