vdom

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	WorkType_Render = "render"
	WorkType_Effect = "effect"
)
View Source
const BindTag = "#bind"
View Source
const ChildrenPropKey = "children"
View Source
const FragmentTag = "#fragment"
View Source
const Html_BindParamTagName = "bindparam"
View Source
const Html_BindPrefix = "#bind:"
View Source
const Html_BindTagName = "bind"
View Source
const Html_GlobalEventPrefix = "#globalevent"
View Source
const Html_ParamPrefix = "#param:"
View Source
const KeyPropKey = "key"
View Source
const ObjectType_Binding = "binding"
View Source
const ObjectType_Func = "func"
View Source
const ObjectType_Ref = "ref"
View Source
const TextTag = "#text"
View Source
const WaveNullTag = "wave:null"
View Source
const WaveTextTag = "wave:text"

Variables

This section is empty.

Functions

func P

func P(propName string, propVal any) map[string]any

func UseAtom added in v0.9.0

func UseAtom[T any](ctx context.Context, atomName string) (T, func(T))

func UseEffect

func UseEffect(ctx context.Context, fn func() func(), deps []any)

func UseId

func UseId(ctx context.Context) string

func UseState

func UseState[T any](ctx context.Context, initialVal T) (T, func(T))

Types

type Atom added in v0.9.0

type Atom struct {
	Val    any
	Dirty  bool
	UsedBy map[string]bool // component waveid -> true
}

type CFunc

type CFunc = func(ctx context.Context, props map[string]any) any

type ChildKey

type ChildKey struct {
	Tag string
	Idx int
	Key string
}

type Component

type Component struct {
	WaveId  string
	Tag     string
	Key     string
	Elem    *VDomElem
	Mounted bool

	// hooks
	Hooks []*Hook

	// #text component
	Text string

	// base component -- vdom, wave elem, or #fragment
	Children []*Component

	// component -> component
	Comp *Component
}

type DomRect added in v0.9.0

type DomRect struct {
	Top    float64 `json:"top"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type EffectWorkElem

type EffectWorkElem struct {
	Id          string
	EffectIndex int
}

type Hook

type Hook struct {
	Init      bool          // is initialized
	Idx       int           // index in the hook array
	Fn        func() func() // for useEffect
	UnmountFn func()        // for useEffect
	Val       any           // for useState, useMemo, useRef
	Deps      []any
}

generic hook structure

type RootElem

type RootElem struct {
	OuterCtx        context.Context
	Root            *Component
	CFuncs          map[string]CFunc
	CompMap         map[string]*Component // component waveid -> component
	EffectWorkQueue []*EffectWorkElem
	NeedsRenderMap  map[string]bool
	Atoms           map[string]*Atom
}

func MakeRoot

func MakeRoot() *RootElem

func (*RootElem) AddEffectWork

func (r *RootElem) AddEffectWork(id string, effectIndex int)

func (*RootElem) AddRenderWork

func (r *RootElem) AddRenderWork(id string)

func (*RootElem) Event

func (r *RootElem) Event(id string, propName string, data any)

func (*RootElem) GetAtom added in v0.9.0

func (r *RootElem) GetAtom(name string) *Atom

func (*RootElem) GetAtomVal added in v0.9.0

func (r *RootElem) GetAtomVal(name string) any

func (*RootElem) GetStateSync added in v0.9.0

func (r *RootElem) GetStateSync(full bool) []VDomStateSync

func (*RootElem) MakeVDom

func (r *RootElem) MakeVDom() *VDomElem

func (*RootElem) RegisterComponent

func (r *RootElem) RegisterComponent(name string, cfunc CFunc)

func (*RootElem) Render

func (r *RootElem) Render(elem *VDomElem)

func (*RootElem) RunWork added in v0.9.0

func (r *RootElem) RunWork()

this will be called by the frontend to say the DOM has been mounted it will eventually send any updated "refs" to the backend as well

func (*RootElem) SetAtomVal added in v0.9.0

func (r *RootElem) SetAtomVal(name string, val any, markDirty bool)

func (*RootElem) SetOuterCtx

func (r *RootElem) SetOuterCtx(ctx context.Context)

type VDomAsyncInitiationRequest added in v0.9.0

type VDomAsyncInitiationRequest struct {
	Type    string `json:"type" tstype:"\"asyncinitiationrequest\""`
	Ts      int64  `json:"ts"`
	BlockId string `json:"blockid,omitempty"`
}

func MakeAsyncInitiationRequest added in v0.9.0

func MakeAsyncInitiationRequest(blockId string) VDomAsyncInitiationRequest

type VDomBackendOpts added in v0.9.0

type VDomBackendOpts struct {
	CloseOnCtrlC         bool `json:"closeonctrlc,omitempty"`
	GlobalKeyboardEvents bool `json:"globalkeyboardevents,omitempty"`
}

type VDomBackendUpdate added in v0.9.0

type VDomBackendUpdate struct {
	Type          string             `json:"type" tstype:"\"backendupdate\""`
	Ts            int64              `json:"ts"`
	BlockId       string             `json:"blockid"`
	Opts          *VDomBackendOpts   `json:"opts,omitempty"`
	RenderUpdates []VDomRenderUpdate `json:"renderupdates,omitempty"`
	StateSync     []VDomStateSync    `json:"statesync,omitempty"`
	RefOperations []VDomRefOperation `json:"refoperations,omitempty"`
	Messages      []VDomMessage      `json:"messages,omitempty"`
}

type VDomBinding added in v0.9.0

type VDomBinding struct {
	Type string `json:"type" tstype:"\"binding\""`
	Bind string `json:"bind"`
}

used in props

type VDomContextVal

type VDomContextVal struct {
	Root    *RootElem
	Comp    *Component
	HookIdx int
}

type VDomCreateContext added in v0.9.0

type VDomCreateContext struct {
	Type    string              `json:"type" tstype:"\"createcontext\""`
	Ts      int64               `json:"ts"`
	Meta    waveobj.MetaMapType `json:"meta,omitempty"`
	Target  *VDomTarget         `json:"target,omitempty"`
	Persist bool                `json:"persist,omitempty"`
}

type VDomElem added in v0.9.0

type VDomElem struct {
	WaveId   string         `json:"waveid,omitempty"` // required, except for #text nodes
	Tag      string         `json:"tag"`
	Props    map[string]any `json:"props,omitempty"`
	Children []VDomElem     `json:"children,omitempty"`
	Text     string         `json:"text,omitempty"`
}

vdom element

func Bind

func Bind(htmlStr string, params map[string]any) *VDomElem

func E

func E(tag string, parts ...any) *VDomElem

func TextElem

func TextElem(text string) VDomElem

func (*VDomElem) Key added in v0.9.0

func (e *VDomElem) Key() string

type VDomEvent added in v0.9.0

type VDomEvent struct {
	WaveId    string `json:"waveid"` // empty for global events
	EventType string `json:"eventtype"`
	EventData any    `json:"eventdata"`
}

type VDomFrontendUpdate added in v0.9.0

type VDomFrontendUpdate struct {
	Type          string            `json:"type" tstype:"\"frontendupdate\""`
	Ts            int64             `json:"ts"`
	BlockId       string            `json:"blockid"`
	CorrelationId string            `json:"correlationid,omitempty"`
	Dispose       bool              `json:"dispose,omitempty"` // the vdom context was closed
	Resync        bool              `json:"resync,omitempty"`  // resync (send all backend data).  useful when the FE reloads
	RenderContext VDomRenderContext `json:"rendercontext,omitempty"`
	Events        []VDomEvent       `json:"events,omitempty"`
	StateSync     []VDomStateSync   `json:"statesync,omitempty"`
	RefUpdates    []VDomRefUpdate   `json:"refupdates,omitempty"`
	Messages      []VDomMessage     `json:"messages,omitempty"`
}

type VDomFunc added in v0.9.0

type VDomFunc struct {
	Fn              any      `json:"-"` // server side function (called with reflection)
	Type            string   `json:"type" tstype:"\"func\""`
	StopPropagation bool     `json:"stoppropagation,omitempty"`
	PreventDefault  bool     `json:"preventdefault,omitempty"`
	GlobalEvent     string   `json:"globalevent,omitempty"`
	Keys            []string `json:"keys,omitempty"` // special for keyDown events a list of keys to "capture"
}

used in props

func (*VDomFunc) CallFn added in v0.9.0

func (vdf *VDomFunc) CallFn()

type VDomKeyboardEvent added in v0.9.0

type VDomKeyboardEvent struct {
	Type     string `json:"type"`
	Key      string `json:"key"`
	Code     string `json:"code"`
	Shift    bool   `json:"shift,omitempty"`
	Control  bool   `json:"ctrl,omitempty"`
	Alt      bool   `json:"alt,omitempty"`
	Meta     bool   `json:"meta,omitempty"`
	Cmd      bool   `json:"cmd,omitempty"`
	Option   bool   `json:"option,omitempty"`
	Repeat   bool   `json:"repeat,omitempty"`
	Location int    `json:"location,omitempty"`
}

matches WaveKeyboardEvent

type VDomMessage added in v0.9.0

type VDomMessage struct {
	MessageType string `json:"messagetype"`
	Message     string `json:"message"`
	StackTrace  string `json:"stacktrace,omitempty"`
	Params      []any  `json:"params,omitempty"`
}

type VDomRef added in v0.9.0

type VDomRef struct {
	Type          string           `json:"type" tstype:"\"ref\""`
	RefId         string           `json:"refid"`
	TrackPosition bool             `json:"trackposition,omitempty"`
	Position      *VDomRefPosition `json:"position,omitempty"`
	HasCurrent    bool             `json:"hascurrent,omitempty"`
}

used in props

func UseVDomRef added in v0.9.0

func UseVDomRef(ctx context.Context) *VDomRef

type VDomRefOperation added in v0.9.0

type VDomRefOperation struct {
	RefId  string `json:"refid"`
	Op     string `json:"op" tsype:"\"focus\""`
	Params []any  `json:"params,omitempty"`
}

type VDomRefPosition added in v0.9.0

type VDomRefPosition struct {
	OffsetHeight       int     `json:"offsetheight"`
	OffsetWidth        int     `json:"offsetwidth"`
	ScrollHeight       int     `json:"scrollheight"`
	ScrollWidth        int     `json:"scrollwidth"`
	ScrollTop          int     `json:"scrolltop"`
	BoundingClientRect DomRect `json:"boundingclientrect"`
}

type VDomRefUpdate added in v0.9.0

type VDomRefUpdate struct {
	RefId      string           `json:"refid"`
	HasCurrent bool             `json:"hascurrent"`
	Position   *VDomRefPosition `json:"position,omitempty"`
}

type VDomRenderContext added in v0.9.0

type VDomRenderContext struct {
	BlockId    string `json:"blockid"`
	Focused    bool   `json:"focused"`
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	RootRefId  string `json:"rootrefid"`
	Background bool   `json:"background,omitempty"`
}

type VDomRenderUpdate added in v0.9.0

type VDomRenderUpdate struct {
	UpdateType string   `json:"updatetype" tstype:"\"root\"|\"append\"|\"replace\"|\"remove\"|\"insert\""`
	WaveId     string   `json:"waveid,omitempty"`
	VDom       VDomElem `json:"vdom"`
	Index      *int     `json:"index,omitempty"`
}

type VDomStateSync added in v0.9.0

type VDomStateSync struct {
	Atom  string `json:"atom"`
	Value any    `json:"value"`
}

type VDomTarget added in v0.9.0

type VDomTarget struct {
	NewBlock  bool `json:"newblock,omitempty"`
	Magnified bool `json:"magnified,omitempty"`
}

target -- to support new targets in the future, like toolbars, partial blocks, splits, etc. default is vdom context inside of a terminal block

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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