vdom

package
v0.8.3-beta.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkType_Render = "render"
	WorkType_Effect = "effect"
)
View Source
const ChildrenPropKey = "children"
View Source
const FragmentTag = "#fragment"
View Source
const KeyPropKey = "key"
View Source
const TextTag = "#text"

Variables

This section is empty.

Functions

func P

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

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 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 {
	Id      string
	Tag     string
	Key     string
	Elem    *Elem
	Mounted bool

	// hooks
	Hooks []*Hook

	// #text component
	Text string

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

	// component -> component
	Comp *Component
}

type EffectWorkElem

type EffectWorkElem struct {
	Id          string
	EffectIndex int
}

type Elem

type Elem struct {
	Id       string         `json:"id,omitempty"` // used for vdom
	Tag      string         `json:"tag"`
	Props    map[string]any `json:"props,omitempty"`
	Children []Elem         `json:"children,omitempty"`
	Text     string         `json:"text,omitempty"`
}

doubles as VDOM structure

func Bind

func Bind(htmlStr string, data map[string]any) *Elem

func E

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

func TextElem

func TextElem(text string) Elem

func (*Elem) Key

func (e *Elem) Key() string

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 id -> component
	EffectWorkQueue []*EffectWorkElem
	NeedsRenderMap  map[string]bool
}

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)

func (*RootElem) MakeVDom

func (r *RootElem) MakeVDom() *Elem

func (*RootElem) RegisterComponent

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

func (*RootElem) Render

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

func (*RootElem) SetOuterCtx

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

type VDomContextVal

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

type VDomFuncType

type VDomFuncType struct {
	Fn              any      `json:"-"` // the actual function to call (called via reflection)
	FuncType        string   `json:"#func"`
	StopPropagation bool     `json:"#stopPropagation,omitempty"`
	PreventDefault  bool     `json:"#preventDefault,omitempty"`
	Keys            []string `json:"#keys,omitempty"` // special for keyDown events a list of keys to "capture"
}

can be used to set preventDefault/stopPropagation

type VDomRefType

type VDomRefType struct {
	RefId   string `json:"#ref"`
	Current any    `json:"current"`
}

func UseRef

func UseRef(ctx context.Context, initialVal any) *VDomRefType

Jump to

Keyboard shortcuts

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