WIP, contributions welcome!
Inertia.js adapter for OCaml.
- Custom root view
- Full template render with passed page object
- "Inertia" render i.e. sending only the data and let the client handle the rendering
- Partial reloads (untested)
- Versioning
- SSR
- Allow other web frameworks to be used (currently coupled with Dream)
- Creating a root view
Before being able to render with Inertia, you need to create a root view. This is a simple function that takes a page object and returns a string. How you do this is up to you, but in the simplest case you can use a string template.
(* app.ml *)
Inertia.set_root_view (fun page_object -> Printf.sprintf {|
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
<div id="app" data-page='%s'></div>
<script type="module" src="/assets/bundle.js"></script>
</body>
</html>
|} (Inertia.Page_object.serialize page_object))
- Calling Inertia
Now you can call Inertia to render your page. Here is an example:
(* app.ml *)
let () =
Dream.run
@@ Dream.logger
@@ Dream.router
[ Dream.get "/" (fun request ->
Inertia.render ~request ~component:"Welcome" ~props:[]
)
; Dream.get "/assets/**" (Dream.static ~loader:asset_loader "")
]
;;
See example for a full example using Inertia.ml with Svelte.