tue

package module
v0.0.0-...-fd1a2a7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 7 Imported by: 0

README

Tue

This repository is being migrated from the legacy Go WebAssembly vue runtime to Tue.

The old reflection/template interpreter runtime and its legacy WebAssembly examples have been removed. Reviewable Tue implementation slices will land in follow-up changes.

The pre-migration Vue runtime and examples remain available on the vue branch.

Current State

  • The GitHub repository and Go module path are github.com/norunners/tue.
  • Tue currently includes the runtime, compiler, CLI, production build, dev server, and formatter slices needed for small internal-app examples.
  • Realistic .tue examples live under examples/. They cover a todo queue, user table, settings form, dashboard, and small path-only hash router.

Try an example from the repository root:

go run ./cmd/tue check examples/todo
go run ./cmd/tue dev examples/todo
go run ./cmd/tue build examples/todo

Verification

For the current baseline, the expected local checks are:

go fmt ./...
go test ./...

License

Documentation

Overview

Package tue contains the runtime used by generated Tue components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Batch

func Batch(fn func())

Batch deduplicates reactive effect reruns until the outermost batch returns.

func RenderHTML

func RenderHTML(node VNode) string

RenderHTML renders a VNode to static HTML.

func Watch

func Watch(effect func()) func()

Watch runs effect immediately, tracks reactive reads, and returns a stop function.

Types

type Attribute

type Attribute struct {
	Name         string
	Value        string
	HasValue     bool
	BoolValue    bool
	HasBoolValue bool
}

Attribute is a static DOM attribute.

func Attr

func Attr(name string, value string) Attribute

Attr returns a static name/value attribute.

func BoolAttr

func BoolAttr(name string) Attribute

BoolAttr returns a static boolean attribute.

func BoolStateAttr

func BoolStateAttr(name string, value bool) Attribute

BoolStateAttr returns a boolean DOM state attribute.

func ClassAttr

func ClassAttr(static string, values ...string) Attribute

ClassAttr returns a normalized class attribute from static and bound classes.

func StyleAttr

func StyleAttr(static string, values ...string) Attribute

StyleAttr returns a normalized style attribute from static and bound styles. It concatenates raw CSS strings and leaves conflicting declarations to the browser cascade.

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 DOMEvent

type DOMEvent interface {
	Value() string
	Checked() bool
}

DOMEvent exposes the DOM event target values used by generated bindings.

type EventBinding

type EventBinding struct {
	Name    string
	Handler func(DOMEvent)
}

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.

func (*Mounted) Unmount

func (m *Mounted) Unmount() error

Unmount calls cleanup functions, clears the target, and calls optional OnUnmounted.

func (*Mounted) Update

func (m *Mounted) Update() error

Update renders the component again and then calls optional OnUpdated.

type Resource

type Resource[T any] interface {
	Value() (T, bool)
	Error() error
	Loading() bool
	Reload()
}

Resource is the async-state interface exposed to component code.

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.

func (*Router) Href

func (r *Router) Href(path string) string

Href returns the link target for a route path.

func (r *Router) Link(path string, attrs []Attribute, children []VNode) VNode

Link returns an anchor VNode for a route path.

func (*Router) Navigate

func (r *Router) Navigate(path string)

Navigate updates the current route path.

func (*Router) View

func (r *Router) View() VNode

View renders the current route handler or the not-found handler.

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]) Get

func (r *StateValue[T]) Get() T

Get returns the current state 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 Element

func Element(tag string, attrs []Attribute, children []VNode) VNode

Element returns an element VNode.

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 Fragment

func Fragment(children []VNode) VNode

Fragment returns a fragment VNode.

func Slot

func Slot(fallback VNode) VNode

Slot renders the current component's default slot or the supplied fallback.

func Text

func Text(value string) VNode

Text returns a text VNode.

func WithScopeAttrs

func WithScopeAttrs(node VNode, attrs ...string) VNode

WithScopeAttrs returns a VNode that applies inherited scoped-CSS attributes to component root elements.

type VNodeType

type VNodeType string

VNodeType identifies the kind of virtual node.

const (
	VNodeTypeElement   VNodeType = "element"
	VNodeTypeText      VNodeType = "text"
	VNodeTypeFragment  VNodeType = "fragment"
	VNodeTypeComponent VNodeType = "component"
)

Directories

Path Synopsis
cmd
tue command
internal
cli

Jump to

Keyboard shortcuts

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