Tutorial — Part 5: Interactive Islands, Tests & Deploy¶
In Part 5, you will learn how to add client-side interactivity without a Node.js bundler (using event directives and Islands compiled from TypeLua to ES Modules), write automated tests with ob test, and ship the entire Mini Blog as a single binary.
1. Progressive Interactivity (@click, @submit.prevent)¶
For lightweight interactions (toggling a modal, confirming a delete, submitting via fetch), .html templates support Vue-style event attributes that compile to standard data-ob-on-* / data-ob-mod-* attributes:
A tiny vanilla script in public/app.js (loaded via {{ asset('app.js') }}) can handle these clicks with zero framework overhead.
2. Interactive Islands (html.island + --target js)¶
When a widget needs rich client-side state (like an interactive Like Counter or live markdown preview on /posts/[id]), Orbita supports Islands Architecture:
- The server renders the full HTML page plus an island container with serialized JSON props via
html.island(name, props, fallback):
-- Inside a route loader (e.g. src/apps/posts/routes/posts/[id].tyl)
local html = require("ob:html")
local like_island = html.render(html.island("LikeButton", {
post_id = post.id,
initial = 12,
}, "Loading..."))
Insert it in [id].html with triple braces:
- Write the interactive island component in TypeLua/Luax (
src/islands/like_button.luax) and compile it to a zero-dependency ES Module withob build --target js:
Orbita's JS compiler emits a clean ES Module with a minimal built-in runtime (useState, mount, hydrateIslands) — no node_modules, no Webpack, no Vite required.
3. Automated Testing (ob test)¶
Create src/apps/posts/posts_test.tyl to test your router, templates, and cache directly in-process (no port binding needed!):
local router = require("ob:router")
ob.test("GET / renders the Mini Blog home page", function()
local app = router.new()
:static("/public", "public")
:mount("/", "src/apps/posts/routes")
local resp = app:handle({ method = "GET", path = "/", headers = {} })
assert(resp.status == 200)
assert(resp.body:find("Latest Posts", 1, true) ~= nil)
end)
ob.test("Static assets return ETag and 304 Not Modified", function()
local app = router.new():static("/public", "public")
local first = app:handle({ method = "GET", path = "/public/styles.css", headers = {} })
assert(first.status == 200)
assert(first.headers["ETag"] ~= nil)
local cached = app:handle({
method = "GET",
path = "/public/styles.css",
headers = { ["If-None-Match"] = first.headers["ETag"] },
})
assert(cached.status == 304)
end)
Run your test suite against an isolated in-memory SQLite database:
4. Deploy as a Single-File Binary¶
Configure [embed] in ob.toml so your routes, .html templates, and public/ assets are bundled into the executable:
Compile the standalone binary:
Ship dist/mini-blog to any server and run it with 12-Factor environment variables — zero external runtime dependencies:
Previous: ← Part 4: Forms, Auth & Caching · Reference: Router Reference (ob:router) · HTML Templates Reference