Skip to content

lessp/inertia.ml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WIP, contributions welcome!

Inertia.ml - Inertia.js adapter for OCaml

Inertia.js adapter for OCaml.

TODO

  • 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)

Usage

  1. 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))
  1. 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published