vdom

package
v0.0.0-...-356c069 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package vdom implements a Virtual DOM, as popularized by React.JS.

Virtual DOM nodes can be constructed with VText and VElem, and patches can be generated with the VNode.Diff method. When run in the browser, patches may be applied to the real DOM to update with minimal changes.

See the builder package for convenient helper functions, and the tea package for a higher-level framework for building apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttrsPatch

type AttrsPatch struct {
	Add    map[string]string
	Remove []string
}

type ChildPatch

type ChildPatch struct {
	Common []Patch
	Drop   int
	Append []VNode
}

type DomNode

type DomNode struct {
	Value any
}

type Event

type Event struct {
	Value any
}

type EventHandler

type EventHandler = *func(Event) any

N.B. the pointer indirection is so these can be compared.

type EventsPatch

type EventsPatch struct {
	Add    map[string]EventHandler
	Remove []string
}

type ModifyPatch

type ModifyPatch struct {
	Attrs    AttrsPatch
	Events   EventsPatch
	Children ChildPatch
}

func (ModifyPatch) Patch

func (ModifyPatch) Patch(p, n DomNode) DomNode

type NopPatch

type NopPatch struct{}

func (NopPatch) Patch

func (NopPatch) Patch(parent, orig DomNode) DomNode

type Patch

type Patch interface {
	// Apply the patch to a DOM node (orig). The first argument
	// is the parent of the dom node being patched. The return
	// value is the new node, which may or may not be the same
	// as the old node.
	Patch(parent, orig DomNode) DomNode
}

type ReplacePatch

type ReplacePatch struct {
	Replacement VNode
}

func (ReplacePatch) Patch

func (p ReplacePatch) Patch(parent, n DomNode) DomNode

type VElem

type VElem struct {
	Tag      string
	Attrs    map[string]string
	Events   map[string]EventHandler
	Children []VNode
}

func (*VElem) Diff

func (ve *VElem) Diff(dst VNode) Patch

func (VElem) ToDomNode

func (ve VElem) ToDomNode() DomNode

type VNode

type VNode interface {
	Diff(dst VNode) Patch
	ToDomNode() DomNode
}

type VText

type VText string

func (VText) Diff

func (vt VText) Diff(dst VNode) Patch

func (VText) ToDomNode

func (vt VText) ToDomNode() DomNode

Directories

Path Synopsis
Package builder provides helpers for constructing VNodes
Package builder provides helpers for constructing VNodes
internal

Jump to

Keyboard shortcuts

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