Documentation
¶
Index ¶
- Constants
- func DefineComponentEx[P any](client *ClientImpl, name string, renderFn func(props P) any) vdom.Component[P]
- func GenerateConfigSchema(root *RootElem) map[string]any
- func GenerateDataSchema(root *RootElem) map[string]any
- func UseEffect(vc *RenderContextImpl, fn func() func(), deps []any)
- func UseId(vc *RenderContextImpl) string
- func UseLocal(vc *RenderContextImpl, initialVal any) string
- func UseRef(vc *RenderContextImpl, hookInitialVal any) any
- func UseRenderTs(vc *RenderContextImpl) int64
- func UseResync(vc *RenderContextImpl) bool
- func UseVDomRef(vc *RenderContextImpl) any
- type AppManifest
- type AppMeta
- type AtomImpl
- type AtomMeta
- type ChildKey
- type ClientImpl
- func (c *ClientImpl) CloseAllModals()
- func (c *ClientImpl) CloseModal(modalId string, result bool)
- func (c *ClientImpl) DeclareSecret(name string, desc string, optional bool)
- func (c *ClientImpl) GetAppManifest() AppManifest
- func (c *ClientImpl) GetAppMeta() AppMeta
- func (c *ClientImpl) GetIsDone() bool
- func (c *ClientImpl) GetSecrets() map[string]SecretMeta
- func (c *ClientImpl) HandleDynFunc(pattern string, fn func(http.ResponseWriter, *http.Request))
- func (c *ClientImpl) PrintAppManifest()
- func (c *ClientImpl) RegisterAppInitFn(fn func() error)
- func (c *ClientImpl) RegisterSSEChannel(connectionId string) chan ssEvent
- func (c *ClientImpl) RunEvents(events []vdom.VDomEvent)
- func (c *ClientImpl) RunMain()
- func (c *ClientImpl) SendAsyncInitiation() error
- func (c *ClientImpl) SendSSEvent(event ssEvent) error
- func (c *ClientImpl) SetAppMeta(m AppMeta)
- func (c *ClientImpl) SetGlobalEventHandler(handler func(event vdom.VDomEvent))
- func (c *ClientImpl) ShowModal(config rpctypes.ModalConfig) chan bool
- func (c *ClientImpl) UnregisterSSEChannel(connectionId string)
- type ComponentImpl
- type EffectContextImpl
- type EffectWorkElem
- type EventContextImpl
- type Hook
- type ModalState
- type RenderContextImpl
- type RenderOpts
- type RootElem
- func (r *RootElem) AtomAddRenderWork(atomName string)
- func (r *RootElem) Event(event vdom.VDomEvent, globalEventHandler func(vdom.VDomEvent))
- func (r *RootElem) GetAtomVal(name string) any
- func (r *RootElem) GetConfigMap() map[string]any
- func (r *RootElem) GetDataMap() map[string]any
- func (r *RootElem) GetRefOperations() []vdom.VDomRefOperation
- func (r *RootElem) MakeRendered() *rpctypes.RenderedElem
- func (r *RootElem) QueueRefOp(op vdom.VDomRefOperation)
- func (r *RootElem) RegisterAtom(name string, atom genAtom)
- func (r *RootElem) RegisterComponent(name string, cfunc any) error
- func (r *RootElem) RemoveAtom(name string)
- func (r *RootElem) Render(elem *vdom.VDomElem, opts *RenderOpts)
- func (r *RootElem) RunWork(opts *RenderOpts)
- func (r *RootElem) SetAtomVal(name string, val any) error
- func (r *RootElem) UpdateRef(updateRef rpctypes.VDomRefUpdate)
- type SecretMeta
Constants ¶
const ( GlobalContextType_async = "async" GlobalContextType_render = "render" GlobalContextType_effect = "effect" GlobalContextType_event = "event" )
const ChildrenPropKey = "children"
const DefaultComponentName = "App"
const DefaultListenAddr = "localhost:0"
const NotifyDebounceTime = 500 * time.Microsecond
const NotifyMaxCadence = 10 * time.Millisecond
const NotifyMaxDebounceTime = 2 * time.Millisecond
const SSEKeepAliveDuration = 5 * time.Second
const TsunamiListenAddrEnvVar = "TSUNAMI_LISTENADDR"
Variables ¶
This section is empty.
Functions ¶
func DefineComponentEx ¶
func GenerateConfigSchema ¶
GenerateConfigSchema generates a JSON schema for all config atoms
func GenerateDataSchema ¶
GenerateDataSchema generates a JSON schema for all data atoms
func UseEffect ¶
func UseEffect(vc *RenderContextImpl, fn func() func(), deps []any)
func UseId ¶
func UseId(vc *RenderContextImpl) string
func UseLocal ¶
func UseLocal(vc *RenderContextImpl, initialVal any) string
func UseRef ¶
func UseRef(vc *RenderContextImpl, hookInitialVal any) any
func UseRenderTs ¶
func UseRenderTs(vc *RenderContextImpl) int64
func UseResync ¶
func UseResync(vc *RenderContextImpl) bool
func UseVDomRef ¶
func UseVDomRef(vc *RenderContextImpl) any
Types ¶
type AppManifest ¶ added in v0.12.3
type AtomImpl ¶
type AtomImpl[T any] struct { // contains filtered or unexported fields }
func MakeAtomImpl ¶
func (*AtomImpl[T]) GetAtomType ¶
type AtomMeta ¶
type AtomMeta struct {
Description string // short, user-facing
Units string // "ms", "GiB", etc.
Min *float64 // optional minimum (numeric types)
Max *float64 // optional maximum (numeric types)
Enum []string // allowed values if finite set
Pattern string // regex constraint for strings
}
AtomMeta provides metadata about an atom for validation and documentation
type ClientImpl ¶
type ClientImpl struct {
Lock *sync.Mutex
Root *RootElem
RootElem *vdom.VDomElem
CurrentClientId string
Meta AppMeta
ServerId string
IsDone bool
DoneReason string
DoneCh chan struct{}
SSEChannels map[string]chan ssEvent // map of connectionId to SSE channel
SSEChannelsLock *sync.Mutex
GlobalEventHandler func(event vdom.VDomEvent)
UrlHandlerMux *http.ServeMux
AppInitFn func() error
AssetsFS fs.FS
StaticFS fs.FS
ManifestFileBytes []byte
// for modals
OpenModals map[string]*ModalState // map of modalId to modal state
OpenModalsLock *sync.Mutex
// for secrets
Secrets map[string]SecretMeta // map of secret name to metadata
SecretsLock *sync.Mutex
// contains filtered or unexported fields
}
func GetDefaultClient ¶
func GetDefaultClient() *ClientImpl
func (*ClientImpl) CloseAllModals ¶
func (c *ClientImpl) CloseAllModals()
CloseAllModals closes all open modals with cancelled result This is called when the FE requests a resync (page refresh or new client)
func (*ClientImpl) CloseModal ¶
func (c *ClientImpl) CloseModal(modalId string, result bool)
CloseModal closes a modal with the given result
func (*ClientImpl) DeclareSecret ¶ added in v0.12.3
func (c *ClientImpl) DeclareSecret(name string, desc string, optional bool)
func (*ClientImpl) GetAppManifest ¶ added in v0.12.3
func (c *ClientImpl) GetAppManifest() AppManifest
func (*ClientImpl) GetAppMeta ¶
func (c *ClientImpl) GetAppMeta() AppMeta
func (*ClientImpl) GetIsDone ¶
func (c *ClientImpl) GetIsDone() bool
func (*ClientImpl) GetSecrets ¶ added in v0.12.3
func (c *ClientImpl) GetSecrets() map[string]SecretMeta
func (*ClientImpl) HandleDynFunc ¶
func (c *ClientImpl) HandleDynFunc(pattern string, fn func(http.ResponseWriter, *http.Request))
func (*ClientImpl) PrintAppManifest ¶ added in v0.12.3
func (c *ClientImpl) PrintAppManifest()
func (*ClientImpl) RegisterAppInitFn ¶ added in v0.12.4
func (c *ClientImpl) RegisterAppInitFn(fn func() error)
func (*ClientImpl) RegisterSSEChannel ¶
func (c *ClientImpl) RegisterSSEChannel(connectionId string) chan ssEvent
func (*ClientImpl) RunEvents ¶
func (c *ClientImpl) RunEvents(events []vdom.VDomEvent)
func (*ClientImpl) RunMain ¶
func (c *ClientImpl) RunMain()
func (*ClientImpl) SendAsyncInitiation ¶
func (c *ClientImpl) SendAsyncInitiation() error
func (*ClientImpl) SendSSEvent ¶
func (c *ClientImpl) SendSSEvent(event ssEvent) error
func (*ClientImpl) SetAppMeta ¶
func (c *ClientImpl) SetAppMeta(m AppMeta)
func (*ClientImpl) SetGlobalEventHandler ¶
func (c *ClientImpl) SetGlobalEventHandler(handler func(event vdom.VDomEvent))
func (*ClientImpl) ShowModal ¶
func (c *ClientImpl) ShowModal(config rpctypes.ModalConfig) chan bool
ShowModal displays a modal and returns a channel that will receive the result
func (*ClientImpl) UnregisterSSEChannel ¶
func (c *ClientImpl) UnregisterSSEChannel(connectionId string)
type ComponentImpl ¶
type ComponentImpl struct {
WaveId string // Unique identifier for this component instance
Tag string // Component type (HTML tag, custom component name, "#text", etc.)
Key string // User-provided key for reconciliation (like React keys)
ContainingComp string // Which vdom component's render function created this ComponentImpl
Elem *vdom.VDomElem // Reference to the current input VDomElem being rendered
Mounted bool // Whether this component is currently mounted
// Hooks system (React-like)
Hooks []*Hook // Array of hooks (state, effects, etc.) attached to this component
// Atom dependency tracking
UsedAtoms map[string]bool // atomName -> true, tracks which atoms this component uses
// Pattern 1: Text nodes
Text string // For "#text" components - stores the actual text content
// Pattern 2: Base/DOM elements with children
Children []*ComponentImpl // For HTML tags, fragments - array of child components
// Pattern 3: Custom components that render to other components
RenderedComp *ComponentImpl // For custom components - points to what this component rendered to
}
ComponentImpl represents a node in the persistent shadow component tree. This is Tsunami's equivalent to React's Fiber nodes - it maintains component identity, state, and lifecycle across renders while the VDomElem input/output structures are ephemeral.
type EffectContextImpl ¶
type EffectContextImpl struct {
WorkElem EffectWorkElem
WorkType string // "run" or "unmount"
Root *RootElem
}
func GetGlobalEffectContext ¶
func GetGlobalEffectContext() *EffectContextImpl
type EffectWorkElem ¶
type EventContextImpl ¶
func GetGlobalEventContext ¶
func GetGlobalEventContext() *EventContextImpl
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 ModalState ¶
type ModalState struct {
Config rpctypes.ModalConfig
ResultChan chan bool // Channel to receive the result (true = confirmed/ok, false = cancelled)
}
type RenderContextImpl ¶
type RenderContextImpl struct {
Root *RootElem
Comp *ComponentImpl
HookIdx int
RenderOpts *RenderOpts
UsedAtoms map[string]bool // Track atoms used during this render
}
func GetGlobalRenderContext ¶
func GetGlobalRenderContext() *RenderContextImpl
func (*RenderContextImpl) GetCompWaveId ¶
func (vc *RenderContextImpl) GetCompWaveId() string
type RenderOpts ¶
type RenderOpts struct {
Resync bool
}
type RootElem ¶
type RootElem struct {
Root *ComponentImpl
RenderTs int64
CFuncs map[string]any // component name => render function
CompMap map[string]*ComponentImpl // component waveid -> component
EffectWorkQueue []*EffectWorkElem
Atoms map[string]genAtom // key: atomName
RefOperations []vdom.VDomRefOperation
Client *ClientImpl
// contains filtered or unexported fields
}
func MakeRoot ¶
func MakeRoot(client *ClientImpl) *RootElem
func (*RootElem) AtomAddRenderWork ¶
func (*RootElem) GetAtomVal ¶
func (*RootElem) GetConfigMap ¶
func (*RootElem) GetDataMap ¶
func (*RootElem) GetRefOperations ¶
func (r *RootElem) GetRefOperations() []vdom.VDomRefOperation
func (*RootElem) MakeRendered ¶
func (r *RootElem) MakeRendered() *rpctypes.RenderedElem
func (*RootElem) QueueRefOp ¶
func (r *RootElem) QueueRefOp(op vdom.VDomRefOperation)
func (*RootElem) RegisterAtom ¶
func (*RootElem) RegisterComponent ¶
func (*RootElem) RemoveAtom ¶
func (*RootElem) RunWork ¶
func (r *RootElem) RunWork(opts *RenderOpts)
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) UpdateRef ¶
func (r *RootElem) UpdateRef(updateRef rpctypes.VDomRefUpdate)