Skip to content

Instantly share code, notes, and snippets.

@fxfactorial
Created July 22, 2016 09:03
Show Gist options
  • Select an option

  • Save fxfactorial/8f59fd3e45cc82231263a58bb4e71af1 to your computer and use it in GitHub Desktop.

Select an option

Save fxfactorial/8f59fd3e45cc82231263a58bb4e71af1 to your computer and use it in GitHub Desktop.
Ideas that I want to work towards
let javascript_from_ocaml
(* Let me do (object%js val count = 10 end) and count becomes a top
level var count = 10; *)
?(js_global_values: 'a Js.t option)
(* of course we want to use js_of_ocaml.ppx by default *)
?(ocaml_pkgs=["js_of_ocaml.ppx"])
(* self-explanatory *)
?(minified=true)
(* Only include JavaScript, no linking of the Dom API at all, only
what's limited to the JavaScript language *)
?(just_javascript=true)
(* These are OCaml .ml files *)
~(src_files:string list)
() =
"One Long JavaScript String"
type server = unit Server.t -> unit Lwt.t
let routes _ = assert false
let () =
let server : server =
[
("/home",
begin fun () ->
let engine = new JavaScriptCore.virtual_machine in
engine#load_javascript ~path:"../static/React.js" ();
engine#load_javascript
~string:(
javascript_from_ocaml ~src_files:["../front_end/homepage.ml"] ()
) ();
(* Last result from last expression evaluated in this virtual
machine, which for us would be server side React rendered
to HTML *)
engine#last_value
end
);
]
|> routes
in
server ()
|> Lwt_main.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment