engine

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 22 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 (
	GlobalContextType_async  = "async"
	GlobalContextType_render = "render"
	GlobalContextType_effect = "effect"
	GlobalContextType_event  = "event"
)
View Source
const ChildrenPropKey = "children"
View Source
const DefaultComponentName = "App"
View Source
const DefaultListenAddr = "localhost:0"
View Source
const NotifyDebounceTime = 500 * time.Microsecond
View Source
const NotifyMaxCadence = 10 * time.Millisecond
View Source
const NotifyMaxDebounceTime = 2 * time.Millisecond
View Source
const SSEKeepAliveDuration = 5 * time.Second
View Source
const TsunamiListenAddrEnvVar = "TSUNAMI_LISTENADDR"

Variables

This section is empty.

Functions

func DefineComponentEx

func DefineComponentEx[P any](client *ClientImpl, name string, renderFn func(props P) any) vdom.Component[P]

func GenerateConfigSchema

func GenerateConfigSchema(root *RootElem) map[string]any

GenerateConfigSchema generates a JSON schema for all config atoms

func GenerateDataSchema

func GenerateDataSchema(root *RootElem) map[string]any

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 AppManifest struct {
	AppMeta      AppMeta               `json:"appmeta"`
	ConfigSchema map[string]any        `json:"configschema"`
	DataSchema   map[string]any        `json:"dataschema"`
	Secrets      map[string]SecretMeta `json:"secrets"`
}

type AppMeta

type AppMeta struct {
	Title     string `json:"title"`
	ShortDesc string `json:"shortdesc"`
	Icon      string `json:"icon"`      // for waveapps, the icon to use (fontawesome names)
	IconColor string `json:"iconcolor"` // for waveapps, the icon color to use (HTML color -- name, hex, rgb)
}

type AtomImpl

type AtomImpl[T any] struct {
	// contains filtered or unexported fields
}

func MakeAtomImpl

func MakeAtomImpl[T any](initialVal T, meta *AtomMeta) *AtomImpl[T]

func (*AtomImpl[T]) GetAtomType

func (a *AtomImpl[T]) GetAtomType() reflect.Type

func (*AtomImpl[T]) GetMeta

func (a *AtomImpl[T]) GetMeta() *AtomMeta

func (*AtomImpl[T]) GetUsedBy

func (a *AtomImpl[T]) GetUsedBy() []string

func (*AtomImpl[T]) GetVal

func (a *AtomImpl[T]) GetVal() any

func (*AtomImpl[T]) SetUsedBy

func (a *AtomImpl[T]) SetUsedBy(waveId string, used bool)

func (*AtomImpl[T]) SetVal

func (a *AtomImpl[T]) SetVal(val any) error

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 ChildKey

type ChildKey struct {
	Tag string
	Idx int
	Key string
}

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 EffectWorkElem struct {
	WaveId      string
	EffectIndex int
	CompTag     string
}

type EventContextImpl

type EventContextImpl struct {
	Event vdom.VDomEvent
	Root  *RootElem
}

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 (r *RootElem) AtomAddRenderWork(atomName string)

func (*RootElem) Event

func (r *RootElem) Event(event vdom.VDomEvent, globalEventHandler func(vdom.VDomEvent))

func (*RootElem) GetAtomVal

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

func (*RootElem) GetConfigMap

func (r *RootElem) GetConfigMap() map[string]any

func (*RootElem) GetDataMap

func (r *RootElem) GetDataMap() map[string]any

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 (r *RootElem) RegisterAtom(name string, atom genAtom)

func (*RootElem) RegisterComponent

func (r *RootElem) RegisterComponent(name string, cfunc any) error

func (*RootElem) RemoveAtom

func (r *RootElem) RemoveAtom(name string)

func (*RootElem) Render

func (r *RootElem) Render(elem *vdom.VDomElem, opts *RenderOpts)

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) SetAtomVal

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

func (*RootElem) UpdateRef

func (r *RootElem) UpdateRef(updateRef rpctypes.VDomRefUpdate)

type SecretMeta added in v0.12.3

type SecretMeta struct {
	Desc     string `json:"desc"`
	Optional bool   `json:"optional"`
}

Jump to

Keyboard shortcuts

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