Documentation
¶
Index ¶
- Constants
- func Class(name string) classAttrWrapper
- func ClassIf(cond bool, name string) classAttrWrapper
- func ClassIfElse(cond bool, name string, elseName string) classAttrWrapper
- func Classes(classes ...any) string
- func Filter[T any](items []T, fn func(T) bool) []T
- func FilterIdx[T any](items []T, fn func(T, int) bool) []T
- func ForEach[T any](items []T, fn func(T) any) []any
- func ForEachIdx[T any](items []T, fn func(T, int) any) []any
- func Fragment(parts ...any) any
- func If(cond bool, part any) any
- func IfElse(cond bool, part any, elsePart any) any
- func P(propName string, propVal any) any
- func PStyle(styleAttr string, propVal any) any
- func Props(props any) map[string]any
- func QueueRefOp(ctx context.Context, ref *VDomRef, op VDomRefOperation)
- func UseAtom[T any](ctx context.Context, atomName string) (T, func(T))
- func UseEffect(ctx context.Context, fn func() func(), deps []any)
- func UseId(ctx context.Context) string
- func UseRenderTs(ctx context.Context) int64
- func UseState[T any](ctx context.Context, initialVal T) (T, func(T))
- func UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(func(T) T))
- type Atom
- type ChildKey
- type Component
- type ComponentImpl
- type DomRect
- type EffectWorkElem
- type Hook
- type RootElem
- func (r *RootElem) AddEffectWork(id string, effectIndex int)
- func (r *RootElem) AddRenderWork(id string)
- func (r *RootElem) Event(id string, propName string, event VDomEvent)
- func (r *RootElem) GetAtom(name string) *Atom
- func (r *RootElem) GetAtomVal(name string) any
- func (r *RootElem) GetRefOperations() []VDomRefOperation
- func (r *RootElem) GetStateSync(full bool) []VDomStateSync
- func (r *RootElem) MakeVDom() *VDomElem
- func (r *RootElem) QueueRefOp(op VDomRefOperation)
- func (r *RootElem) RegisterComponent(name string, cfunc any) error
- func (r *RootElem) Render(elem *VDomElem)
- func (r *RootElem) RunWork()
- func (r *RootElem) SetAtomVal(name string, val any, markDirty bool)
- func (r *RootElem) SetOuterCtx(ctx context.Context)
- func (r *RootElem) UpdateRef(updateRef VDomRefUpdate)
- type VDomAsyncInitiationRequest
- type VDomBackendOpts
- type VDomBackendUpdate
- type VDomBinding
- type VDomContextVal
- type VDomCreateContext
- type VDomElem
- type VDomEvent
- type VDomFrontendUpdate
- type VDomFunc
- type VDomKeyboardEvent
- type VDomMessage
- type VDomRef
- type VDomRefOperation
- type VDomRefPosition
- type VDomRefUpdate
- type VDomRenderContext
- type VDomRenderUpdate
- type VDomSimpleRef
- type VDomStateSync
- type VDomTarget
- type VDomTargetToolbar
- type VDomTransferElem
- type WaveKeyboardEvent
- type WavePointerData
Constants ¶
View Source
const ( BackendUpdate_InitialChunkSize = 50 // Size for initial chunks that contain both TransferElems and StateSync BackendUpdate_ChunkSize = 100 // Size for subsequent chunks )
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 ClassIfElse ¶ added in v0.9.2
func QueueRefOp ¶ added in v0.9.2
func QueueRefOp(ctx context.Context, ref *VDomRef, op VDomRefOperation)
func UseRenderTs ¶ added in v0.9.2
func UseStateWithFn ¶ added in v0.9.2
Types ¶
type ComponentImpl ¶ added in v0.9.2
type ComponentImpl 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 []*ComponentImpl
// component -> component
Comp *ComponentImpl
}
type EffectWorkElem ¶
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 *ComponentImpl
RenderTs int64
CFuncs map[string]any
CompMap map[string]*ComponentImpl // component waveid -> component
EffectWorkQueue []*EffectWorkElem
NeedsRenderMap map[string]bool
Atoms map[string]*Atom
RefOperations []VDomRefOperation
}
func (*RootElem) AddEffectWork ¶
func (*RootElem) AddRenderWork ¶
func (*RootElem) GetAtomVal ¶ added in v0.9.0
func (*RootElem) GetRefOperations ¶ added in v0.9.2
func (r *RootElem) GetRefOperations() []VDomRefOperation
func (*RootElem) GetStateSync ¶ added in v0.9.0
func (r *RootElem) GetStateSync(full bool) []VDomStateSync
func (*RootElem) QueueRefOp ¶ added in v0.9.2
func (r *RootElem) QueueRefOp(op VDomRefOperation)
func (*RootElem) RegisterComponent ¶
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 (*RootElem) SetOuterCtx ¶
func (*RootElem) UpdateRef ¶ added in v0.9.2
func (r *RootElem) UpdateRef(updateRef VDomRefUpdate)
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 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"`
HasWork bool `json:"haswork,omitempty"`
RenderUpdates []VDomRenderUpdate `json:"renderupdates,omitempty"`
TransferElems []VDomTransferElem `json:"transferelems,omitempty"`
StateSync []VDomStateSync `json:"statesync,omitempty"`
RefOperations []VDomRefOperation `json:"refoperations,omitempty"`
Messages []VDomMessage `json:"messages,omitempty"`
}
func SplitBackendUpdate ¶ added in v0.9.2
func SplitBackendUpdate(update *VDomBackendUpdate) []*VDomBackendUpdate
SplitBackendUpdate splits a large VDomBackendUpdate into multiple smaller updates The first update contains all the core fields, while subsequent updates only contain array elements that need to be appended
func (*VDomBackendUpdate) CreateTransferElems ¶ added in v0.9.2
func (beUpdate *VDomBackendUpdate) CreateTransferElems()
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 *ComponentImpl
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
type VDomEvent ¶ added in v0.9.0
type VDomEvent struct {
WaveId string `json:"waveid"`
EventType string `json:"eventtype"` // usually the prop name (e.g. onClick, onKeyDown)
GlobalEventType string `json:"globaleventtype,omitempty"`
TargetValue string `json:"targetvalue,omitempty"`
TargetChecked bool `json:"targetchecked,omitempty"`
TargetName string `json:"targetname,omitempty"`
TargetId string `json:"targetid,omitempty"`
KeyData *WaveKeyboardEvent `json:"keydata,omitempty"`
MouseData *WavePointerData `json:"mousedata,omitempty"`
}
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
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 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
type VDomRefOperation ¶ added in v0.9.0
type VDomRefPosition ¶ added in v0.9.0
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 VDomRenderUpdate ¶ added in v0.9.0
type VDomRenderUpdate struct {
UpdateType string `json:"updatetype" tstype:"\"root\"|\"append\"|\"replace\"|\"remove\"|\"insert\""`
WaveId string `json:"waveid,omitempty"`
VDomWaveId string `json:"vdomwaveid,omitempty"`
VDom *VDomElem `json:"vdom,omitempty"` // these get removed for transfer (encoded to transferelems)
Index *int `json:"index,omitempty"`
}
type VDomSimpleRef ¶ added in v0.9.2
type VDomSimpleRef[T any] struct { Current T `json:"current"` }
type VDomStateSync ¶ added in v0.9.0
type VDomTarget ¶ added in v0.9.0
type VDomTarget struct {
NewBlock bool `json:"newblock,omitempty"`
Magnified bool `json:"magnified,omitempty"`
Toolbar *VDomTargetToolbar `json:"toolbar,omitempty"`
}
target -- to support new targets in the future, like toolbars, partial blocks, splits, etc. default is vdom context inside of a terminal block
type VDomTargetToolbar ¶ added in v0.9.2
type VDomTransferElem ¶ added in v0.9.2
type VDomTransferElem struct {
WaveId string `json:"waveid,omitempty"` // required, except for #text nodes
Tag string `json:"tag"`
Props map[string]any `json:"props,omitempty"`
Children []string `json:"children,omitempty"`
Text string `json:"text,omitempty"`
}
the over the wire format for a vdom element
func ConvertElemsToTransferElems ¶ added in v0.9.2
func ConvertElemsToTransferElems(elems []VDomElem) []VDomTransferElem
func DedupTransferElems ¶ added in v0.9.2
func DedupTransferElems(elems []VDomTransferElem) []VDomTransferElem
type WaveKeyboardEvent ¶ added in v0.9.2
type WaveKeyboardEvent struct {
Type string `json:"type" tstype:"\"keydown\"|\"keyup\"|\"keypress\"|\"unknown\""`
Key string `json:"key"` // KeyboardEvent.key
Code string `json:"code"` // KeyboardEvent.code
Repeat bool `json:"repeat,omitempty"`
Location int `json:"location,omitempty"` // KeyboardEvent.location
// modifiers
Shift bool `json:"shift,omitempty"`
Control bool `json:"control,omitempty"`
Alt bool `json:"alt,omitempty"`
Meta bool `json:"meta,omitempty"`
Cmd bool `json:"cmd,omitempty"` // special (on mac it is meta, on windows/linux it is alt)
Option bool `json:"option,omitempty"` // special (on mac it is alt, on windows/linux it is meta)
}
type WavePointerData ¶ added in v0.9.2
type WavePointerData struct {
Button int `json:"button"`
Buttons int `json:"buttons"`
ClientX int `json:"clientx,omitempty"`
ClientY int `json:"clienty,omitempty"`
PageX int `json:"pagex,omitempty"`
PageY int `json:"pagey,omitempty"`
ScreenX int `json:"screenx,omitempty"`
ScreenY int `json:"screeny,omitempty"`
MovementX int `json:"movementx,omitempty"`
MovementY int `json:"movementy,omitempty"`
// Modifiers
Shift bool `json:"shift,omitempty"`
Control bool `json:"control,omitempty"`
Alt bool `json:"alt,omitempty"`
Meta bool `json:"meta,omitempty"`
Cmd bool `json:"cmd,omitempty"` // special (on mac it is meta, on windows/linux it is alt)
Option bool `json:"option,omitempty"` // special (on mac it is alt, on windows/linux it is meta)
}
Click to show internal directories.
Click to hide internal directories.