Documentation
¶
Overview ¶
Package jsruntime is waffle's in-process JavaScript engine: it transpiles a user's JSX/TSX React document and runs it entirely inside the Go process to produce a waffle-tree/v1 JSON document — no Node.js at render time.
The pipeline is pure Go end to end:
esbuild (github.com/evanw/esbuild) — transpile JSX/TSX + bundle, in memory goja (github.com/dop251/goja) — execute the bundled React program
React itself (react.production.min.js) and the @waffle/react runtime are embedded and resolved by an esbuild plugin from strings, so nothing is read from disk or node_modules. goja is the single JS engine; there is no sidecar.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is a rendered document on a live goja VM. Unlike Render, it keeps the runtime alive so function render-props (kept as closures in the VM) can be evaluated per page via EvalCallback. It is NOT safe for concurrent use — the underlying goja VM is single-threaded — but layout/pagination is sequential.
func (*Instance) EvalCallback ¶
EvalCallback evaluates the render-prop callback id with ctxJSON (the page context: pageNumber, totalPages, …) and returns a JSON array of waffle-tree nodes produced by the callback.
type Options ¶
type Options struct {
// TypeScript selects the TSX loader for the user source (JSX by default).
TypeScript bool
// Filename labels the user source in error messages (default "document.jsx").
Filename string
}
Options configures how a source is transpiled.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a compiled React document, ready to render with varying props. It holds an esbuild-bundled, goja-compiled program; it is safe to Render many times (each Render runs on a fresh goja VM).
func Compile ¶
Compile transpiles and bundles a JSX/TSX React document into an executable program. The source's default export must be a <Document> element or a function returning one (given props).
func (*Program) BundledSource ¶
BundledSource returns the transpiled+bundled JS (for debugging/tests).
func (*Program) Instantiate ¶
Instantiate runs the program with props and returns a live Instance whose Tree() is the waffle-tree/v1 JSON.