Documentation
¶
Overview ¶
Package gox provides JSX-like syntax for Go and the core types for virtual DOM trees.
Index ¶
- Constants
- func WalkTree(root VNode, walker Walker)
- type Component
- type Props
- type RenderFunc
- type Renderer
- type VNode
- func E(typ any, props Props, children ...VNode) VNode
- func Element(typ any, props Props, children ...VNode) VNode
- func Empty() VNode
- func Fragment(children ...VNode) VNode
- func Map[T any](items []T, fn func(T) VNode) []VNode
- func MapIndex[T any](items []T, fn func(int, T) VNode) []VNode
- func Spread(nodes []VNode) VNode
- func Text(content string) VNode
- func V(value any) VNode
- func When(condition bool, child VNode) VNode
- func WhenElse(condition bool, ifTrue, ifFalse VNode) VNode
- type WalkFunc
- type Walker
Constants ¶
const ( TextNodeType = "__text__" FragmentNodeType = "__fragment__" )
NodeType constants for special node types.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RenderFunc ¶
RenderFunc is a function type that implements Renderer.
func (RenderFunc) Render ¶
func (f RenderFunc) Render(vnode VNode) error
Render implements the Renderer interface.
type Renderer ¶
type Renderer interface {
// Render processes a VNode tree and produces output.
Render(vnode VNode) error
}
Renderer is the interface for connecting VNode trees to actual implementations. Users implement this interface to bridge gox output to their tree system (e.g., TUI libraries, HTML DOM, custom tree structures).
type VNode ¶
type VNode struct {
Type any // string for intrinsic elements, Component for components
Props Props
Children []VNode
}
VNode is the core tree node type.
func Element ¶
Element creates a VNode for an element (intrinsic or component). typ can be a string (for intrinsic elements like "div", "span") or a Component function.
func Map ¶
Map applies a function to each element and returns the resulting VNodes. Useful for rendering lists: {gox.Map(items, func(item Item) VNode { return <ItemView item={item} /> })}
func MapIndex ¶
MapIndex applies a function with index to each element and returns the resulting VNodes.
func Spread ¶
Spread expands a slice of VNodes into children. Useful when you have a []VNode and need to pass as children.
func V ¶
V converts an arbitrary value to a VNode. If the value is already a VNode, it's returned as-is. If it's a string, it's wrapped as a Text node. If it's a []VNode, it's wrapped as a Fragment. Numeric types and booleans are converted to their string representation. Panics for unsupported types (channels, functions, etc.).
func When ¶
When returns child if condition is true, else empty VNode. Useful for conditional rendering: {gox.When(showExtra, <Extra />)}
func (VNode) GetTextContent ¶
GetTextContent returns the text content if this is a text node.
func (VNode) IsComponent ¶
IsComponent returns true if this VNode represents a component.
func (VNode) IsFragment ¶
IsFragment returns true if this VNode is a fragment.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast defines the AST types for gox files.
|
Package ast defines the AST types for gox files. |
|
cmd
|
|
|
gox
command
gox is a preprocessor that transforms .gox files containing Go + JSX syntax into pure .go files.
|
gox is a preprocessor that transforms .gox files containing Go + JSX syntax into pure .go files. |
|
Package formatter provides formatting for .gox files.
|
Package formatter provides formatting for .gox files. |
|
Package generator transforms gox AST into Go source code.
|
Package generator transforms gox AST into Go source code. |
|
Package lsp implements a Language Server Protocol proxy for gox files.
|
Package lsp implements a Language Server Protocol proxy for gox files. |
|
Package parser parses gox files into an AST.
|
Package parser parses gox files into an AST. |