A library for building interactive, server-rendered LiveView UIs over WebSocket in Pony.
Livery is beta quality software that will change frequently. Expect breaking changes. That said, you should feel comfortable using it in your projects.
- Install corral
corral add github.com/ponylang/livery.git --version 0.1.0corral fetchto fetch your dependenciesuse "livery"to include this packagecorral run -- ponycto compile your application
Note: livery depends on the ssl package transitively through mare. See the ssl installation instructions for OpenSSL setup, and pass the appropriate -D flag when compiling (e.g., corral run -- ponyc -Dopenssl_3.0.x).
Define a LiveView class, register routes, and start a listener:
use "templates"
use "json"
use lori = "lori"
use "livery"
class CounterView is LiveView
let _template: HtmlTemplate val
new create() ? =>
_template = HtmlTemplate.parse(
"""
<div>
<h1>Count: {{ count }}</h1>
<button lv-click="increment">+</button>
</div>
""")?
fun ref mount(socket: Socket ref) =>
socket.assign("count", "0")
fun ref handle_event(event: String val, payload: JsonValue,
socket: Socket ref)
=>
try
let current = socket.get_assign("count")?.string()?.i64()?
if event == "increment" then
socket.assign("count", (current + 1).string())
end
end
fun box render(assigns: Assigns box): String ? =>
_template.render(assigns.template_values())?
actor Main
new create(env: Env) =>
let router = Router
router.route("/counter",
{(): LiveView ref^ ? => CounterView.create()?} val)
Listener(lori.TCPListenAuth(env.root), "0.0.0.0", "8081",
router.build(), env.err)See the examples directory for more.