Pipeline
template -> GCode -> GCompile -> GTpl
GTPL is a TypeScript library for reactive template systems built around Direct DOM and Proxy. Inspired by Vue, Angular AOT, and JSX, it delivers efficient reactive UI updates in a compact 11kB JavaScript package.
template -> GCode -> GCompile -> GTpl
State changes are observed via Proxy and mapped to bind trees for direct DOM updates.
Use built-ins like g-if, g-for, g-switch or register your own directives.
.cls { color: #00f; }
.weight { font-weight: bold }
div[custom='value'] { background-color: #ff0; }
Template expressions are wrapped in {{ ... }}. GTPL supports variables, constants, chained functions and formulas.
| API | Purpose | Example |
|---|---|---|
| gtpl.jit.GCode(html) | Transform template HTML into AOT code string. | const aot = GCode(template) |
| gtpl.jit.GCompile(aot) | Compile generated AOT string into element generator function. | const gen = GCompile(aot) |
| new gtpl.GTpl(options) | Create reactive instance bound to a root object. | new GTpl({ root, generator: gen }) |
| instance.addTo(node) | Append rendered template to target node. | instance.addTo(container) |
| instance.watch(path, cb) | Observe reactive path changes from GTPL state. | instance.watch('foo', cb) |
| instance.destroy() | Unmount elements, listeners and watchers. | instance.destroy() |
Security note: g-inner writes directly to innerHTML. Use trusted HTML sources only.