app

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: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxShortDescLen = 120
View Source
const TsunamiCloseOnStdinEnvVar = "TSUNAMI_CLOSEONSTDIN"

Variables

This section is empty.

Functions

func DeclareSecret added in v0.12.3

func DeclareSecret(secretName string, meta *SecretMeta) string

func DeepCopy

func DeepCopy[T any](v T) T

DeepCopy creates a deep copy of the input value using JSON marshal/unmarshal. Panics on JSON errors.

func DefineComponent

func DefineComponent[P any](name string, renderFn func(props P) any) vdom.Component[P]

func HandleDynFunc

func HandleDynFunc(pattern string, fn func(http.ResponseWriter, *http.Request))

HandleDynFunc registers a dynamic HTTP handler function with the internal http.ServeMux. The pattern MUST start with "/dyn/" to be valid. This allows registration of dynamic routes that can be handled at runtime.

func ListStaticFiles added in v0.12.4

func ListStaticFiles() ([]fs.FileInfo, error)

ListStaticFiles returns FileInfo for all files in the embedded static filesystem. The Name() of each FileInfo will be the full path prefixed with "static/" (e.g., "static/config.json"), which can be passed directly to ReadStaticFile or OpenStaticFile.

func OpenStaticFile added in v0.12.4

func OpenStaticFile(path string) (fs.File, error)

OpenStaticFile opens a file from the embedded static filesystem. The path MUST start with "static/" (e.g., "static/config.json"). Returns an fs.File or an error if the file doesn't exist or can't be opened.

func PrintAppManifest added in v0.12.3

func PrintAppManifest()

func Ptr

func Ptr[T any](v T) *T

func QueueRefOp

func QueueRefOp(ref *vdom.VDomRef, op vdom.VDomRefOperation)

QueueRefOp queues a reference operation to be executed on the DOM element. Operations include actions like "focus", "scrollIntoView", etc. If the ref is nil or not current, the operation is ignored. This function must be called within a component context.

func ReadStaticFile added in v0.12.4

func ReadStaticFile(path string) ([]byte, error)

ReadStaticFile reads a file from the embedded static filesystem. The path MUST start with "static/" (e.g., "static/config.json"). Returns the file contents or an error if the file doesn't exist or can't be read.

func RegisterAppInitFn added in v0.12.4

func RegisterAppInitFn(fn func() error)

RegisterAppInitFn registers a single setup function that is called before the app starts running. Only one setup function is allowed, so calling this will replace any previously registered setup function.

func RegisterEmbeds

func RegisterEmbeds(assetsFilesystem fs.FS, staticFilesystem fs.FS, manifest []byte)

RegisterEmbeds is used internally by generated code and should not be called directly.

func RunMain

func RunMain()

RunMain is used internally by generated code and should not be called directly.

func SendAsyncInitiation

func SendAsyncInitiation() error

SendAsyncInitiation notifies the frontend that the backend has updated state and requires a re-render. Normally the frontend calls the backend in response to events, but when the backend changes state independently (e.g., from a background process), this function gives the frontend a "nudge" to update.

func SetAppMeta added in v0.12.3

func SetAppMeta(meta AppMeta)

func SetGlobalEventHandler

func SetGlobalEventHandler(handler func(event vdom.VDomEvent))

func SetShortDesc

func SetShortDesc(shortDesc string)

func SetTitle

func SetTitle(title string)

func UseAfter

func UseAfter(duration time.Duration, timeoutFn func(), deps []any)

UseAfter manages a timeout lifecycle within a component. It creates a timer that calls the provided function after the specified duration. The timer is automatically canceled on dependency changes or component unmount. This hook must be called within a component context.

func UseAlertModal

func UseAlertModal() (modalOpen bool, triggerAlert func(config ModalConfig))

UseAlertModal returns a boolean indicating if the modal is open and a function to trigger it

func UseConfirmModal

func UseConfirmModal() (modalOpen bool, triggerConfirm func(config ModalConfig))

UseConfirmModal returns a boolean indicating if the modal is open and a function to trigger it

func UseEffect

func UseEffect(fn func() func(), deps []any)

UseEffect is the tsunami analog to React's useEffect hook. It queues effects to run after the render cycle completes. The function can return a cleanup function that runs before the next effect or when the component unmounts. Dependencies use shallow comparison, just like React. This hook must be called within a component context.

func UseGoRoutine

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

UseGoRoutine manages a goroutine lifecycle within a component. It spawns a new goroutine with the provided function when dependencies change, and automatically cancels the context on dependency changes or component unmount. This hook must be called within a component context.

func UseId

func UseId() string

UseId returns the underlying component's unique identifier (UUID). The ID persists across re-renders but is recreated when the component is recreated, following React component lifecycle. This hook must be called within a component context.

func UseRef

func UseRef[T any](val T) *vdom.VDomSimpleRef[T]

UseRef is the tsunami analog to React's useRef hook. It provides a mutable ref object that persists across re-renders. Unlike UseVDomRef, this is not tied to DOM elements but holds arbitrary values. This hook must be called within a component context.

func UseRenderTs

func UseRenderTs() int64

UseRenderTs returns the timestamp of the current render. This hook must be called within a component context.

func UseResync

func UseResync() bool

UseResync returns whether the current render is a resync operation. Resyncs happen on initial app loads or full refreshes, as opposed to incremental renders which happen otherwise. This hook must be called within a component context.

func UseTicker

func UseTicker(interval time.Duration, tickFn func(), deps []any)

UseTicker manages a ticker lifecycle within a component. It creates a ticker that calls the provided function at regular intervals. The ticker is automatically stopped on dependency changes or component unmount. This hook must be called within a component context.

func UseVDomRef

func UseVDomRef() *vdom.VDomRef

UseVDomRef provides a reference to a DOM element in the VDOM tree. It returns a VDomRef that can be attached to elements for direct DOM access. The ref will not be current on the first render - refs are set and become current after client-side mounting. This hook must be called within a component context.

Types

type AppMeta added in v0.12.3

type AppMeta engine.AppMeta

type Atom

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

Atom[T] represents a typed atom implementation

func ConfigAtom

func ConfigAtom[T any](name string, defaultValue T, meta *AtomMeta) Atom[T]

func DataAtom

func DataAtom[T any](name string, defaultValue T, meta *AtomMeta) Atom[T]

func SharedAtom

func SharedAtom[T any](name string, defaultValue T) Atom[T]

func UseLocal

func UseLocal[T any](initialVal T) Atom[T]

UseLocal creates a component-local atom that is automatically cleaned up when the component unmounts. The atom is created with a unique name based on the component's wave ID and hook index. This hook must be called within a component context.

func (Atom[T]) AtomName

func (a Atom[T]) AtomName() string

AtomName implements the vdom.Atom interface

func (Atom[T]) Get

func (a Atom[T]) Get() T

Get returns the current value of the atom. When called during component render, it automatically registers the component as a dependency for this atom, ensuring the component re-renders when the atom value changes.

func (Atom[T]) Set

func (a Atom[T]) Set(newVal T)

Set updates the atom's value to the provided new value and triggers re-rendering of any components that depend on this atom. This method cannot be called during render cycles - use effects or event handlers instead.

func (Atom[T]) SetFn

func (a Atom[T]) SetFn(fn func(T) T)

SetFn updates the atom's value by applying the provided function to the current value. The function receives a copy of the current atom value, which can be safely mutated without affecting the original data. The return value from the function becomes the new atom value. This method cannot be called during render cycles.

type AtomMeta

type AtomMeta struct {
	Desc    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 ModalConfig

type ModalConfig struct {
	Icon       string     `json:"icon,omitempty"`       // Optional icon to display (emoji or icon name)
	Title      string     `json:"title"`                // Modal title
	Text       string     `json:"text,omitempty"`       // Optional body text
	OkText     string     `json:"oktext,omitempty"`     // Optional OK button text (defaults to "OK")
	CancelText string     `json:"canceltext,omitempty"` // Optional Cancel button text for confirm modals (defaults to "Cancel")
	OnClose    func()     `json:"-"`                    // Optional callback for alert modals when dismissed
	OnResult   func(bool) `json:"-"`                    // Optional callback for confirm modals with the result (true = confirmed, false = cancelled)
}

ModalConfig contains all configuration options for modals

type SecretMeta added in v0.12.3

type SecretMeta struct {
	Desc     string
	Optional bool
}

SecretMeta provides metadata about a secret for documentation and validation

Jump to

Keyboard shortcuts

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