Documentation
¶
Overview ¶
Package vuka is the runtime of Vuka programs: Result and Option.
Vuka code writes Result[User], Ok(u), Err(e), Some(x) and None unqualified; the transpiler points them here. Go code uses the package like any other.
Index ¶
- func Arg[T any](c *Call, i int) T
- func As[T any](v any) T
- func AttachLive(c Stateful, inst LiveInstance)
- func AttrOf[T any](c *Call) (T, bool)
- func EventName(attr string) string
- func FieldAttrs[T any]() map[string][]any
- func FieldAttrsOf(t reflect.Type) map[string][]any
- func Handler(f func(r *http.Request) (Node, error)) http.Handler
- func Instance[F any](s *Instances, build func() F) F
- func KeyText(k any) string
- func MountLive(ctx context.Context, c Stateful) error
- func RegisterFields[T any](attrs map[string][]any)
- func RegisterTempl(key string, components ...TemplComponent)
- func SettleState(c Stateful)
- func SortBy[T any](xs []T, orders ...Order[T])
- func String(ctx context.Context, n Node) (string, error)
- func TrackedState(c Stateful) (tracked, changed bool)
- func Void(tag string) bool
- func Walk(ctx context.Context, n Node, r Renderer) error
- func WithLiveHost(ctx context.Context, h LiveHost) context.Context
- func Write(w http.ResponseWriter, r *http.Request, n Node) error
- type Assign
- type Attr
- type Boundary
- type Builder
- type Call
- type CompareRef
- type ComponentNode
- type Decl
- type Decorated
- type Decorator
- type Element
- type Event
- type EventHandler
- type Field
- type FieldPath
- func (p FieldPath) Attr(ptr any) bool
- func (p FieldPath) Attrs() []any
- func (p FieldPath) Fields() []reflect.StructField
- func (p FieldPath) Index() [][]int
- func (p FieldPath) Names() []string
- func (p FieldPath) Root() reflect.Type
- func (p FieldPath) String() string
- func (p FieldPath) Value(root any) (any, bool)
- type File
- type Frame
- type Func
- type Group
- type HTMLRenderer
- type Instances
- type Live
- type LiveHost
- type LiveInstance
- type Node
- func Child(v any) Node
- func Component(site string, key any, props Stateful) Node
- func El(tag string, attrs []Attr, children ...Node) Node
- func ErrorBoundary(fallback func(err error) Node, children ...Node) Node
- func F(fp uint64, shape string, kids ...Node) Node
- func Fragment(children ...Node) Node
- func Nodes(build func(add func(Node))) Node
- func RootAttrs(n Node, attrs ...Attr) (Node, bool)
- func Safe(html string) Node
- func Text(v any) Node
- func Try(n Node, err error) Node
- type NodeFunc
- type NullableRef
- type Op
- type Option
- type Order
- type OrderedRef
- type Param
- type Pred
- type RawHTML
- type Ref
- func (r Ref[T, V]) Asc() Order[T]
- func (r Ref[T, V]) Attr(ptr any) bool
- func (r Ref[T, V]) Attrs() []any
- func (r Ref[T, V]) Desc() Order[T]
- func (r Ref[T, V]) Eq(v V) Pred[T]
- func (r Ref[T, V]) FieldPath() FieldPath
- func (r Ref[T, V]) Get(t T) V
- func (r Ref[T, V]) In(vs ...V) Pred[T]
- func (r Ref[T, V]) Lookup(t T) (V, bool)
- func (r Ref[T, V]) Name() string
- func (r Ref[T, V]) Ne(v V) Pred[T]
- func (r Ref[T, V]) Path() []string
- type Related
- type Renderer
- type Result
- type Stateful
- type Static
- type Statics
- type StringRef
- type Style
- type TemplComponent
- type TextNode
- type Tree
- type TreeHost
- type TreeList
- type TreeRef
- type TryNode
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v0.2.0
As converts a value held in an any back to T; nil is T's zero value. It panics, naming both types, when a decorator put something else there.
func AttachLive ¶ added in v0.7.0
func AttachLive(c Stateful, inst LiveInstance)
AttachLive binds a component to its session instance. Package live calls it.
func EventName ¶ added in v0.7.0
EventName is the DOM event an on… attribute names: onClick is click, onKeyDown keydown.
func FieldAttrs ¶ added in v0.7.0
FieldAttrs is the typed attributes of T's fields, by field name: for
type Post struct {
Title string @Char{Max: 200}
}
FieldAttrs[Post]()["Title"] is []any{Char{Max: 200}}. It is nil for a type whose fields carry none.
func FieldAttrsOf ¶ added in v0.7.0
FieldAttrsOf is FieldAttrs for a reflect.Type.
func Handler ¶ added in v0.5.0
Handler serves the Node f builds for each request through templ.Handler: rendered in full with the request's context, then sent as text/html. An error from f or from rendering answers 500 with only the status text.
func Instance ¶
Instance returns the instantiation of a generic decorated function whose type is F, building it the first time.
func MountLive ¶ added in v0.7.0
MountLive runs c's Mount method, if it has one: Mount(), Mount() error, Mount(context.Context) or Mount(context.Context) error.
func RegisterFields ¶ added in v0.7.0
RegisterFields records the typed attributes written on T's fields, by field name. Generated code calls it at init, for every struct with field attributes.
func RegisterTempl ¶ added in v0.6.0
func RegisterTempl(key string, components ...TemplComponent)
RegisterTempl records the components compiled from a .templ file. Generated code calls it.
func SettleState ¶ added in v0.9.0
func SettleState(c Stateful)
SettleState marks c's Assigns unchanged, after a render.
func SortBy ¶ added in v0.7.0
SortBy sorts xs by the orders, the first deciding, the next breaking ties; the sort is stable.
func TrackedState ¶ added in v0.9.0
TrackedState reports whether c's state is all Assigns (tracked), and whether one of them changed since SettleState. Package live calls it.
func Void ¶ added in v0.5.0
Void reports whether tag is a void element: no children, no closing tag.
func Walk ¶ added in v0.5.0
Walk sends n's tree to r. Frames, Groups, Builders and Child conversions are flattened (r never sees them); a TryNode with an error stops the walk with it; a Boundary walks its children into a recording first, and replays it into r — or, when they fail, walks Fallback(err) instead, so r never sees the failed part. Inside a Boundary an opaque Node is rendered while recording and replayed as Opaque of its HTML (a RawHTML). Children on a void element are an error. The first error from r stops the walk.
func WithLiveHost ¶ added in v0.7.0
WithLiveHost is ctx carrying h.
Types ¶
type Assign ¶ added in v0.9.0
type Assign[T any] struct { // contains filtered or unexported fields }
Assign is a stateful component's state value whose changes a live session tracks: Set and Update mark it changed. A component whose state fields (its unexported ones, except those tagged `vuka:"-"`) are all Assigns renders again only when one of them changed or its props did; otherwise the session keeps its last render without calling Render.
type Row struct {
vuka.Live
Name string // a prop
qty vuka.Assign[int] // state
}
func (r *Row) Inc() { r.qty.Update(func(n int) int { return n + 1 }) }
Render must then read nothing but props and Assigns (and fields tagged `vuka:"-"`, which must not change what it renders); in tests (or with VUKA_LIVE_VERIFY=1) the session renders skipped components anyway and fails when the result differs.
type Attr ¶ added in v0.2.0
Attr is one attribute of an element. In HTML it renders the way templ renders the same attribute written as an expression:
- nil and false omit it, true writes it bare;
- class takes a string or anything templ.Classes does ([]string, map[string]bool, templ.KV, …);
- style takes a Style or anything templ's style attributes do, sanitized by templ (an unsafe property or value becomes templ's placeholder);
- href on a and link, action on form and data on object are URLs: templ.URL keeps relative URLs and http, https, mailto, tel, ftp and ftps, and turns anything else into about:invalid#TemplFailedSanitizationURL; a templ.SafeURL passes as is. Like templ, other attributes (img src, …) aren't URL-checked;
- a templ.ComponentScript writes its Call; a Node is rendered and escaped; anything else goes through fmt.Sprint and is escaped (templ.ResolveAttributeValue).
className and htmlFor name class and for. Names must be letters, digits, - _ : and . (templ only ever sees literal names; here a dynamic one could smuggle in another attribute), else Render fails.
type Boundary ¶ added in v0.5.0
Boundary renders Children or, when one of them fails, Fallback(err) in place of everything they produced.
type Builder ¶ added in v0.5.0
type Builder func(add func(Node))
Builder produces children as it runs: a loop, if or match block. It runs once per Render or Walk, each added child rendered as it is added.
type Call ¶ added in v0.2.0
type Call struct {
Name string
Receiver any // the receiver, for a method
Args []any // the arguments; a variadic parameter is one slice
Results []any // the results, once Next has run (or Return was called)
// contains filtered or unexported fields
}
Call is one call of a decorated function, passed down its decorators.
func NewCall ¶ added in v0.2.0
NewCall starts a call through chain, ending in invoke. Generated code calls it.
func (*Call) Attr ¶ added in v0.2.0
Attr fills ptr with the declaration's typed attribute of ptr's element type, reporting whether there is one: var r Route; c.Attr(&r).
func (*Call) Context ¶ added in v0.2.0
Context is the call's context.Context argument, or context.Background().
func (*Call) Next ¶ added in v0.2.0
func (c *Call) Next()
Next runs the rest of the chain: the next decorator, or the function itself. It can be called more than once.
func (*Call) Return ¶ added in v0.2.0
Return sets the results without running the function; the rest of the chain is skipped unless Next is called.
type CompareRef ¶ added in v0.7.0
CompareRef is a reference to a field whose type orders itself, such as time.Time.
func CompareRefOf ¶ added in v0.7.0
func CompareRefOf[T any, V interface{ Compare(V) int }](index [][]int, _ func(*T)) CompareRef[T, V]
func (CompareRef[T, V]) Asc ¶ added in v0.7.0
func (r CompareRef[T, V]) Asc() Order[T]
func (CompareRef[T, V]) Desc ¶ added in v0.7.0
func (r CompareRef[T, V]) Desc() Order[T]
func (CompareRef[T, V]) Ge ¶ added in v0.7.0
func (r CompareRef[T, V]) Ge(v V) Pred[T]
Ge is the predicate field >= v, by V's Compare.
func (CompareRef[T, V]) Gt ¶ added in v0.7.0
func (r CompareRef[T, V]) Gt(v V) Pred[T]
Gt is the predicate field > v, by V's Compare.
func (CompareRef[T, V]) Le ¶ added in v0.7.0
func (r CompareRef[T, V]) Le(v V) Pred[T]
Le is the predicate field <= v, by V's Compare.
func (CompareRef[T, V]) Lt ¶ added in v0.7.0
func (r CompareRef[T, V]) Lt(v V) Pred[T]
Lt is the predicate field < v, by V's Compare.
type ComponentNode ¶ added in v0.7.0
ComponentNode is a stateful component's tag, <Counter Start={5} />: Props is a fresh value carrying the attributes, never mounted itself. Site (the tag's place in the source), Key and the instance rendering it identify the instance a session keeps.
type Decl ¶ added in v0.6.0
type Decl struct {
Name string // "main.ShowPet", "PetAdmin.Index"
Pkg string // the package's import path
File string // the source file's base name, and the line of the name, for messages
Line int
Attrs []any // the declaration's typed attributes
// Func is the function, wrapped by the declaration's other decorators, so
// calling it runs them too. For a method it is the method expression:
// func(recv, args…).
Func any
Recv reflect.Type // the receiver type, for a method
Params []Param // the parameters, receiver excluded
Results []reflect.Type
Variadic bool
}
Decl describes a declaration for a declarer: a decorator of type func(d *vuka.Decl), which runs once at program start rather than around each call. Declarers register things — routes, commands, jobs — from the declarations they decorate:
func Get(path string) func(*vuka.Decl) {
return func(d *vuka.Decl) { routes[path] = d.Func }
}
func FuncDecl ¶ added in v0.6.0
FuncDecl describes a function for its declarers, given its parameters' names. Generated code calls it.
func MethodDecl ¶ added in v0.6.0
MethodDecl describes a method, d.Func being its method expression. Generated code calls it.
type Decorated ¶
type Decorated[F any] struct { // contains filtered or unexported fields }
Decorated holds a decorated function, built from its decorators on first use. Vuka generates one per decorated function or method.
type Decorator ¶ added in v0.2.0
type Decorator func(c *Call)
Decorator wraps a call of any function: it runs code around c.Next(), may change c.Args before it, read or replace c.Results after it, call it again (retries) or not at all (caches). Written once, it decorates any function or method:
func logged(c *vuka.Call) {
fmt.Println("calling", c.Name, c.Args)
c.Next()
}
A decorator with parameters is a function returning one; it runs once per decorated function, so state it keeps isn't shared between functions.
type Element ¶ added in v0.5.0
Element is an element: <Tag Attrs>Children</Tag>. A void element (br, img, input, …; see Void) has no closing tag, and children on one are an error; in HTML, html is preceded by the doctype.
Text inside script follows templ's Go expressions in a script: it is JSON-encoded (templ's runtime.ScriptContentOutsideStringLiteral), so it arrives as a quoted JS string with < > & escaped. templ has no expressions inside style; here text in a style element is written as is with "</" written "<\/", so it can't end the element.
type Event ¶ added in v0.7.0
type Event struct {
Target string `json:"target"`
Type string `json:"event,omitempty"`
Value string `json:"value,omitempty"`
Key string `json:"key,omitempty"`
Form url.Values `json:"form,omitempty"`
}
Event is what the browser reports of an event, and what a handler taking a vuka.Event receives. Target is the handler's id; Type the DOM event; Value the target element's value (for a checkbox, "true" or "false"); Key the key of a keyboard event; Form the fields of the form a submit event comes from.
type EventHandler ¶ added in v0.7.0
type EventHandler struct{ Fn any }
EventHandler is an on… attribute's expression on an element: onClick={c.Inc}. Under a live session it renders as data-vk-on-<event>="<handler id>" and the session calls Fn when the browser reports the event; without one it renders nothing. A templ.ComponentScript renders as templ renders it.
type Field ¶ added in v0.3.0
type Field struct {
Name string
Type reflect.Type
Tag reflect.StructTag
Attrs []any // the field's typed attributes
Injected bool // a parameter of New: not blank, not tagged inject:"-"
}
Field is a field of a struct.
type FieldPath ¶ added in v0.7.0
type FieldPath struct {
// contains filtered or unexported fields
}
FieldPath is where a field reference leads from its root struct: one step per field written (Post.Author.Name has two), each step an index path that passes through embedded structs. Between steps it goes through a pointer or a Related value.
func (FieldPath) Attr ¶ added in v0.7.0
Attr fills ptr with the last field's typed attribute of ptr's element type.
func (FieldPath) Fields ¶ added in v0.7.0
func (p FieldPath) Fields() []reflect.StructField
Fields are the struct fields of each step.
type File ¶ added in v0.6.0
type File string
File names a file of the program's source tree. A string literal written where a decorator or typed attribute takes a File is checked when the program is compiled (it must exist, in the package's directory or below) and embedded into the binary; the File then holds "importpath:relative/path" and Bytes returns the embedded content:
func Template(view vuka.File) func(*vuka.Decl) { … view.Bytes() … }
@Template("views/pet.html")
func showPet(id int) Pet { … }
For a .templ file, TemplComponents also gives its components. The file may be in a subdirectory that is a package of its own (views/pets.templ with `package views`): its File is then that package's ("module/views:pets.templ") and the generated code imports it.
func (File) Bytes ¶ added in v0.6.0
Bytes is the file's content: embedded, or for a File Vuka didn't embed (a conversion such as vuka.File("x.txt")) read from disk.
type Frame ¶ added in v0.9.0
Frame is a piece of JSX as the compiler saw it: a tree's root, a block's body (one per loop iteration or branch taken), or a component tag's children. It renders exactly as its Kids would; under a live session it is also a frame of the render tree, whose markup splits into statics (what the source fixes, identical every render) and dynamics (what Go expressions produce), so a session sends the statics once and then only the dynamics that changed.
FP fingerprints what its statics are made of: its tags, attribute names and literal values, text, and where the expressions go — pieces of JSX that render the same statics share it, however they are formatted. Shape describes Kids, one item each, in the order they appear:
t text from the source
h b c a dynamic: an {expr} child, a {for}/{if}/{match} block, a component tag
E…(…) an element: a flag per attribute, s (a literal) or d (an expression),
then its children's items in parentheses
G(…) a fragment, <>…</>
Hand-written trees need no Frame: a Node that isn't one is a single dynamic of the frame around it, rendered to HTML.
type Func ¶ added in v0.2.0
type Func struct {
Name string // "main.charge", "Store.Save"
Attrs []any // the declaration's typed attributes
ErrIndex int // the trailing error result's index, or -1
CtxIndex int // the context.Context argument's index, or -1
Zero func() []any
}
Func describes a decorated function. Vuka generates one per function.
type HTMLRenderer ¶ added in v0.5.0
type HTMLRenderer struct {
// contains filtered or unexported fields
}
HTMLRenderer is the Renderer writing HTML: what Render does. Escaping and sanitizing are templ's (see Attr and Element).
func NewHTMLRenderer ¶ added in v0.5.0
func NewHTMLRenderer(ctx context.Context, w io.Writer) *HTMLRenderer
NewHTMLRenderer is an HTMLRenderer writing to w, unbuffered; ctx renders Node attribute values.
func (*HTMLRenderer) Close ¶ added in v0.5.0
func (h *HTMLRenderer) Close(e *Element) error
func (*HTMLRenderer) Opaque ¶ added in v0.5.0
func (h *HTMLRenderer) Opaque(ctx context.Context, n Node) error
func (*HTMLRenderer) Open ¶ added in v0.5.0
func (h *HTMLRenderer) Open(e *Element) error
func (*HTMLRenderer) Raw ¶ added in v0.5.0
func (h *HTMLRenderer) Raw(html string) error
func (*HTMLRenderer) Text ¶ added in v0.5.0
func (h *HTMLRenderer) Text(s string) error
type Instances ¶
type Instances struct {
// contains filtered or unexported fields
}
Instances holds a generic decorated function's instantiations, each built from its decorators on first use.
type Live ¶ added in v0.7.0
type Live struct {
// contains filtered or unexported fields
}
Live, embedded by value in a struct whose pointer has a Render() Node method, makes the struct a stateful component:
type Counter struct {
vuka.Live
Start int // exported fields are props, set from the tag's attributes
n int // unexported fields are state
}
Rendered without a live session (vuka.String, Handler, …) a stateful component mounts and renders once, as plain HTML. Under a session (package live) it is an instance that keeps its state between renders and answers the events of the elements it renders.
type LiveHost ¶ added in v0.7.0
type LiveHost interface {
Component(ctx context.Context, n *ComponentNode, w io.Writer) error
Handler(ctx context.Context, fn any) string
Keyed(ctx context.Context, key any) context.Context
}
LiveHost renders stateful components and registers event handlers for a live session. Package live implements it; ctx carries it.
type LiveInstance ¶ added in v0.7.0
LiveInstance is a session's side of a component instance. Package live implements it.
type Node ¶ added in v0.5.0
Node is anything that renders HTML: what a JSX expression evaluates to. It is templ.Component itself, so Vuka components are templ components and templ components are Vuka children, with nothing in between.
The Nodes built here (*Element, TextNode, RawHTML, Group, Builder, TryNode, Boundary, *Frame) are also a tree any Renderer can Walk; any other Node — a templ component, a NodeFunc — is opaque: it can only render HTML. Nodes are immutable values; rendering one concurrently is safe.
func Child ¶ added in v0.5.0
Child is a {expr} child: a Node as is, nil as nothing, an error as its message, a []Node or []any as each element in turn, anything else as Text.
func ErrorBoundary ¶ added in v0.5.0
ErrorBoundary renders children, or — when one of them fails — fallback(err) in place of everything they wrote.
func RootAttrs ¶ added in v0.9.0
RootAttrs is n with attrs added after its root element's own, when n is an element or a frame of one element; ok is false otherwise.
type NodeFunc ¶ added in v0.5.0
type NodeFunc = templ.ComponentFunc
NodeFunc is a function rendering HTML: templ.ComponentFunc.
type NullableRef ¶ added in v0.7.0
NullableRef is a reference to a field that can be nil or None.
func NullableRefOf ¶ added in v0.7.0
func NullableRefOf[T, V any](index [][]int, _ func(*T)) NullableRef[T, V]
func (NullableRef[T, V]) IsNil ¶ added in v0.7.0
func (r NullableRef[T, V]) IsNil() Pred[T]
IsNil is the predicate that the field is nil or None (or that a nil pointer or relation is on the way).
func (NullableRef[T, V]) NotNil ¶ added in v0.7.0
func (r NullableRef[T, V]) NotNil() Pred[T]
NotNil is the predicate that the field is neither nil nor None.
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is a value that may be absent. The zero Option is None.
func None ¶
None is an absent value. Vuka code writes plain None; the transpiler fills in T from where the value goes.
func (Option[T]) Unwrap ¶
func (o Option[T]) Unwrap() T
Unwrap is the value; it panics when o is None.
type Order ¶ added in v0.7.0
Order is an ordering of Ts by a field: Post.Views.Desc().
type OrderedRef ¶ added in v0.7.0
OrderedRef is a reference to a number field (or any cmp.Ordered type).
func OrderedRefOf ¶ added in v0.7.0
func OrderedRefOf[T any, V cmp.Ordered](index [][]int, _ func(*T)) OrderedRef[T, V]
func (OrderedRef[T, V]) Asc ¶ added in v0.7.0
func (r OrderedRef[T, V]) Asc() Order[T]
func (OrderedRef[T, V]) Desc ¶ added in v0.7.0
func (r OrderedRef[T, V]) Desc() Order[T]
func (OrderedRef[T, V]) Ge ¶ added in v0.7.0
func (r OrderedRef[T, V]) Ge(v V) Pred[T]
Ge is the predicate field >= v.
func (OrderedRef[T, V]) Gt ¶ added in v0.7.0
func (r OrderedRef[T, V]) Gt(v V) Pred[T]
Gt is the predicate field > v.
func (OrderedRef[T, V]) Le ¶ added in v0.7.0
func (r OrderedRef[T, V]) Le(v V) Pred[T]
Le is the predicate field <= v.
func (OrderedRef[T, V]) Lt ¶ added in v0.7.0
func (r OrderedRef[T, V]) Lt(v V) Pred[T]
Lt is the predicate field < v.
type Param ¶ added in v0.6.0
Param is a parameter of a declared function: its name as written ("" when unnamed) and type.
type Pred ¶ added in v0.7.0
type Pred[T any] struct { Op Op Path FieldPath // the field tested; zero for and, or and not Value any // the operand: a V, a []V for in; nil for isnil, notnil and the combinations Preds []Pred[T] // the operands of and, or and not // contains filtered or unexported fields }
Pred is a condition on a T, built from field references — Post.Views.Gt(100), vuka.Or(…) — and kept as data, so a query builder can translate it (Op, the field's Path and attributes, the Value) or Match can test it in memory. Being typed by T, a Pred[User] can't be passed where a Pred[Post] is wanted.
type Ref ¶ added in v0.7.0
type Ref[T, V any] struct { // contains filtered or unexported fields }
Ref is a field reference: Post.Title in Vuka source, a typed handle on the Title field of Post, of type V. Through pointer, struct and Related fields it reaches further: Post.Author.Name. Its methods build predicates and orderings over T, or read the field.
Vuka picks the most capable kind for the field's type: StringRef for strings, OrderedRef for numbers, CompareRef for types with a Compare method (time.Time), NullableRef for pointers, slices, maps, interfaces and Options, and Ref for the rest.
func RefOf ¶ added in v0.7.0
RefOf, OrderedRefOf, StringRefOf, CompareRefOf and NullableRefOf make references; Vuka generates the calls. The function is never called: it is there so the compiler and the editor see the fields the reference names.
func (Ref[T, V]) Attr ¶ added in v0.7.0
Attr fills ptr with the field's typed attribute of ptr's element type.
func (Ref[T, V]) Get ¶ added in v0.7.0
func (r Ref[T, V]) Get(t T) V
Get is the field's value in t, or V's zero value when a nil pointer or relation is on the way.
func (Ref[T, V]) Lookup ¶ added in v0.7.0
Lookup is the field's value in t; false when a nil pointer or relation is on the way.
type Related ¶ added in v0.7.0
type Related[T any] interface{ Related() *T }
Related is implemented by a field type that refers to a T held elsewhere, such as a foreign key. A field reference continues through it into T's fields: with Author of a type implementing Related[User], Post.Author.Name is a Ref[Post, string]. Related returns nil when there is no T.
type Renderer ¶ added in v0.5.0
type Renderer interface {
Open(e *Element) error // before children
Close(e *Element) error // after children (not called for void elements)
Text(s string) error
Raw(html string) error // Safe content
Opaque(ctx context.Context, n Node) error // a component that only renders HTML (templ, NodeFunc)
}
Renderer receives a node tree in document order; Walk drives it. The HTML renderer behind every Node's Render is one; package term is another.
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result is a value or an error. It is Ok when it holds no error; the zero Result is Ok with T's zero value.
func (Result[T]) Unwrap ¶
func (r Result[T]) Unwrap() T
Unwrap is the value; it panics when r failed.
type Stateful ¶ added in v0.7.0
type Stateful interface {
Render() Node
// contains filtered or unexported methods
}
Stateful is a stateful component: a pointer to a struct embedding Live, with a Render method.
type Static ¶ added in v0.2.0
type Static[V any] struct { V V }
Static is the storage of a static field of a generic type: one per instantiation, so Model[User] and Model[Order] each have their own.
type Statics ¶ added in v0.2.0
type Statics struct {
// contains filtered or unexported fields
}
Statics holds one generic static field's instantiations.
type StringRef ¶ added in v0.7.0
type StringRef[T any, V ~string] struct{ OrderedRef[T, V] }
StringRef is a reference to a string field.
func StringRefOf ¶ added in v0.7.0
func (StringRef[T, V]) Contains ¶ added in v0.7.0
Contains is the predicate that the field contains s.
func (StringRef[T, V]) EndsWith ¶ added in v0.7.0
EndsWith is the predicate that the field ends with s.
func (StringRef[T, V]) StartsWith ¶ added in v0.7.0
StartsWith is the predicate that the field starts with s.
type Style ¶ added in v0.5.0
Style is an inline style: style={vuka.Style{"color": "red"}}, rendered by templ as "color:red;" sorted by property, each property and value sanitized.
type TemplComponent ¶ added in v0.6.0
TemplComponent is a component of a .templ file: its name, the generated function (func(params…) templ.Component) and its parameters' names.
func TemplComponents ¶ added in v0.6.0
func TemplComponents(f File) ([]TemplComponent, bool)
TemplComponents are the components of an embedded .templ file, in source order: all of them for a file of the referencing package, the exported ones for a file of a subdirectory's package.
type Tree ¶ added in v0.9.0
Tree is a frame of a live render tree: the markup of a piece of JSX as statics, the strings its source fixes, around dynamics, what its expressions rendered. Its HTML is Statics[0] + Dyn[0] + Statics[1] + … + Statics[len(Dyn)]. A dynamic is a string of HTML, a nested *Tree, a *TreeList (a block's items) or a TreeRef (a stateful component instance, rendered by the session as a tree of its own).
Key identifies the statics: the frame's fingerprint in its render context. Two trees with the same Key have the same Statics, which are shared and must not be modified.
func BuildTree ¶ added in v0.9.0
BuildTree renders n as a render tree. A Frame becomes a Tree split as its shape says; anything else is a frame of one dynamic. ctx should carry a live host; with verify, statics already known for a Key are rendered again and compared, and a difference is an error.
func OpaqueTree ¶ added in v0.9.0
OpaqueTree is a frame with no statics of its own around dyns.
type TreeHost ¶ added in v0.9.0
type TreeHost interface {
LiveHost
ComponentRef(ctx context.Context, n *ComponentNode) (id string, err error)
}
TreeHost is a LiveHost that can render a stateful component's tag as a reference to its instance. Package live implements it.
type TreeList ¶ added in v0.9.0
TreeList is a {for}, {if} or {match} block's items, a frame per iteration or branch taken. Keys are the items' keys, from the key attribute of each item's first element or component tag; nil unless every item has one.
type TreeRef ¶ added in v0.9.0
type TreeRef string
TreeRef is a stateful component instance in a render tree: its id.
type TryNode ¶ added in v0.5.0
TryNode is a (Node, error) component's result as a child: Err fails the render, else Node renders.
type Type ¶ added in v0.2.0
type Type struct {
Name string // "main.User"
Reflect reflect.Type
Attrs []any // the declaration's typed attributes
New any // the constructor, for a struct; nil otherwise
Fields []Field // the struct's fields
}
Type describes a decorated type, for a type decorator:
func Model(t *vuka.Type) { registry[t.Name] = t.Reflect }
For a struct, New is a constructor taking each dependency field as a parameter (or the type's own static New, when it declares one), which is the shape dependency-injection containers take:
func Component(t *vuka.Type) { providers = append(providers, t.New) }
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vuka
command
Command vuka transpiles Vuka source to Go and runs the go command over it.
|
Command vuka transpiles Vuka source to Go and runs the go command over it. |
|
vukavet
module
|
|
|
internal
|
|
|
format
Package format formats Vuka source: the Go in it exactly as gofmt does, and its JSX the way Prettier lays out markup, without changing what it renders.
|
Package format formats Vuka source: the Go in it exactly as gofmt does, and its JSX the way Prettier lays out markup, without changing what it renders. |
|
load
Package load finds Vuka packages in a module and supplies what transpiling them needs from the go command: build-context file selection, export data for imports, and the overlay that puts generated files in front of the compiler.
|
Package load finds Vuka packages in a module and supplies what transpiling them needs from the go command: build-context file selection, export data for imports, and the overlay that puts generated files in front of the compiler. |
|
Package live runs stateful components for a connected browser: a Session keeps the component instances of one page, calls their event handlers and Update methods, and answers each with the HTML of the components whose output changed.
|
Package live runs stateful components for a connected browser: a Session keeps the component instances of one page, calls their event handlers and Update methods, and answers each with the HTML of the components whose output changed. |
|
internal/demo
Package demo is stateful components compiled by the Vuka compiler, for the live package's property tests and benchmarks.
|
Package demo is stateful components compiled by the Vuka compiler, for the live package's property tests and benchmarks. |
|
livetest
Package livetest is a reference client of the live protocol, in Go: it keeps what a browser runtime keeps — the page's HTML for v1, each instance's render tree for v2 — and applies the server's messages the way a runtime must, so tests can check that what a client ends up with is what the server rendered.
|
Package livetest is a reference client of the live protocol, in Go: it keeps what a browser runtime keeps — the page's HTML for v1, each instance's render tree for v2 — and applies the server's messages the way a runtime must, so tests can check that what a client ends up with is what the server rendered. |
|
Package templx passes children to templ components.
|
Package templx passes children to templ components. |
|
Package term renders a vuka Node tree as terminal text: headings, paragraphs word-wrapped at a width, lists, tables, quotes, code, links, and inline bold/italic/underline as ANSI styles when Color is on.
|
Package term renders a vuka Node tree as terminal text: headings, paragraphs word-wrapped at a width, lists, tables, quotes, code, links, and inline bold/italic/underline as ANSI styles when Color is on. |
|
Package transpile turns Vuka source into Go.
|
Package transpile turns Vuka source into Go. |
