Documentation
¶
Overview ¶
Package tue contains the runtime used by generated Tue components.
Index ¶
- func Batch(fn func())
- func RenderHTML(node VNode) string
- func Watch(effect func()) func()
- type Attribute
- type Comp
- type CompInstance
- type Computed
- type ComputedValue
- type Context
- type DOMEvent
- type EventBinding
- type Mounted
- type Resource
- type ResourceValue
- type Route
- type RouteMatch
- type Router
- type State
- type StateValue
- type TrustedHTML
- type VNode
- func Component(name string, factory func() *CompInstance) VNode
- func ComponentWithUpdate(name string, factory func() *CompInstance, update func(*CompInstance)) VNode
- func Element(tag string, attrs []Attribute, children []VNode) VNode
- func ElementWithEvents(tag string, attrs []Attribute, events []EventBinding, children []VNode) VNode
- func ElementWithTrustedHTML(tag string, attrs []Attribute, events []EventBinding, innerHTML TrustedHTML) VNode
- func Fragment(children []VNode) VNode
- func Slot(fallback VNode) VNode
- func Text(value string) VNode
- func WithScopeAttrs(node VNode, attrs ...string) VNode
- type VNodeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attribute ¶
Attribute is a static DOM attribute.
func BoolStateAttr ¶
BoolStateAttr returns a boolean DOM state attribute.
type Comp ¶
type Comp[T any] struct{}
Comp declares generated component fields for compiler discovery. T must be an anonymous struct whose fields use prop, event, or state tags. The marker has no runtime state and does not require initialization.
type CompInstance ¶
type CompInstance struct {
Component any
Render func() VNode
DefaultSlot func() VNode
// contains filtered or unexported fields
}
CompInstance is a generated component instance.
func CompOf ¶
func CompOf[C any](component *C, render func(*C) VNode) *CompInstance
CompOf returns a component wrapper for generated code.
type Computed ¶
type Computed[T any] interface { Get() T Watch(func(T)) func() }
Computed is the read interface exposed to component code.
type ComputedValue ¶
type ComputedValue[T any] struct { // contains filtered or unexported fields }
ComputedValue is the concrete runtime storage for a computed value.
func ComputedOfFunc ¶
func ComputedOfFunc[T any](compute func() T) *ComputedValue[T]
ComputedOfFunc returns a lazy, cached computed value backed by a function.
func (*ComputedValue[T]) Get ¶
func (c *ComputedValue[T]) Get() T
Get returns the current computed value, recomputing only when dirty.
func (*ComputedValue[T]) Watch ¶
func (c *ComputedValue[T]) Watch(effect func(T)) func()
Watch observes computed changes and returns a stop function.
type Context ¶
type Context interface {
OnCleanup(func())
}
Context is passed to optional component Init methods.
type EventBinding ¶
EventBinding is a native DOM event handler generated from @event attributes.
func EventOf ¶
func EventOf(name string, handler func()) EventBinding
EventOf returns a native DOM event binding.
func OnChecked ¶
func OnChecked(name string, handler func(bool)) EventBinding
OnChecked returns a native DOM event binding that receives target.checked.
func OnValue ¶
func OnValue(name string, handler func(string)) EventBinding
OnValue returns a native DOM event binding that receives target.value.
type Mounted ¶
type Mounted struct {
// contains filtered or unexported fields
}
Mounted is a live component mounted into a runtime target.
func Mount ¶
func Mount(target string, component *CompInstance) (*Mounted, error)
Mount renders a component into a browser target under js/wasm.
type ResourceValue ¶
type ResourceValue[T any] struct { // contains filtered or unexported fields }
ResourceValue is the concrete runtime storage for async resource state.
func ResourceOfContextFunc ¶
func ResourceOfContextFunc[T any](ctx Context, load func(stdcontext.Context) (T, error)) *ResourceValue[T]
ResourceOfContextFunc returns a resource backed by a context-aware load function and starts the initial load immediately. Cancellation is cooperative: Reload and component cleanup cancel the load context, and stale results are ignored if a loader keeps running after cancellation.
func ResourceOfFunc ¶
func ResourceOfFunc[T any](ctx Context, load func() (T, error)) *ResourceValue[T]
ResourceOfFunc returns a resource backed by a load function and starts the initial load immediately.
func (*ResourceValue[T]) Error ¶
func (r *ResourceValue[T]) Error() error
Error returns the most recent load error.
func (*ResourceValue[T]) Loading ¶
func (r *ResourceValue[T]) Loading() bool
Loading reports whether a load is currently in flight.
func (*ResourceValue[T]) Reload ¶
func (r *ResourceValue[T]) Reload()
Reload starts a new load and invalidates any older in-flight result.
func (*ResourceValue[T]) Value ¶
func (r *ResourceValue[T]) Value() (T, bool)
Value returns the loaded value and whether a value is currently available.
type Route ¶
type Route struct {
Path string
Render func(RouteMatch) VNode
}
Route is one explicit router table entry.
type RouteMatch ¶
type RouteMatch struct {
Path string
Pattern string
Params map[string]string
RawQuery string
Query url.Values
Found bool
}
RouteMatch is the current matched route state. The router matches path segments only. RawQuery preserves the query string, while Query and QueryParam expose parsed url.Values when the query is valid.
func (RouteMatch) Param ¶
func (m RouteMatch) Param(name string) string
Param returns a matched path parameter by name.
func (RouteMatch) QueryParam ¶
func (m RouteMatch) QueryParam(name string) string
QueryParam returns the first query value by name.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router keeps reactive route state for a small explicit route table.
func RouterOf ¶
func RouterOf(ctx Context, routes []Route, notFound func(RouteMatch) VNode) *Router
RouterOf returns a router backed by the current browser hash path under js/wasm and an in-memory path elsewhere. Prefer creating routers from a component Init method with the provided Context so browser hash listeners are released when the component unmounts.
func (*Router) Current ¶
func (r *Router) Current() RouteMatch
Current returns the current route match and tracks it as a reactive read.
type State ¶
type State[T any] interface { Get() T Set(T) Watch(func(T)) func() }
State is the read/write interface used by generated component state.
type StateValue ¶
type StateValue[T any] struct { // contains filtered or unexported fields }
StateValue is the concrete runtime storage for reactive state.
func StateOf ¶
func StateOf[T any](value T) *StateValue[T]
StateOf returns reactive state with an initial value.
func (*StateValue[T]) Set ¶
func (r *StateValue[T]) Set(value T)
Set updates the state value and invalidates dependents.
func (*StateValue[T]) Watch ¶
func (r *StateValue[T]) Watch(effect func(T)) func()
Watch observes state changes and returns a stop function.
type TrustedHTML ¶
type TrustedHTML string
TrustedHTML is an explicitly trusted raw HTML payload for v-html.
type VNode ¶
type VNode struct {
Type VNodeType
Key string
Tag string
Attrs []Attribute
Events []EventBinding
Children []VNode
Text string
InnerHTML TrustedHTML
HasInnerHTML bool
ComponentFactory func() *CompInstance
ComponentUpdater func(*CompInstance)
// contains filtered or unexported fields
}
VNode is the generated render tree consumed by the runtime.
func Component ¶
func Component(name string, factory func() *CompInstance) VNode
Component returns a component VNode backed by a lazy generated factory.
func ComponentWithUpdate ¶
func ComponentWithUpdate(name string, factory func() *CompInstance, update func(*CompInstance)) VNode
ComponentWithUpdate returns a component VNode that can refresh generated input bindings on an existing component instance during patching.
func ElementWithEvents ¶
func ElementWithEvents(tag string, attrs []Attribute, events []EventBinding, children []VNode) VNode
ElementWithEvents returns an element VNode with native event bindings.
func ElementWithTrustedHTML ¶
func ElementWithTrustedHTML(tag string, attrs []Attribute, events []EventBinding, innerHTML TrustedHTML) VNode
ElementWithTrustedHTML returns an element VNode with trusted raw inner HTML.
func WithScopeAttrs ¶
WithScopeAttrs returns a VNode that applies inherited scoped-CSS attributes to component root elements.