Skip to content

Commit

Permalink
Webapp: separate ui and logic, fixes by moving to Hooked from React
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinepouille committed Sep 26, 2024
1 parent d51243f commit e59ed94
Show file tree
Hide file tree
Showing 100 changed files with 817 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Make Javascript app
run: |
opam exec -- make Kappapp.tar.gz build/site/index.html
cp -r gui/viz .
cp -r gui/js_lib/viz .
mv build/Kappapp.tar.gz .
mv build/site .
- name: Archive Javascript app
Expand Down
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.26.1
version = 0.26.2
profile=conventional
margin=80
if-then-else=k-r
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Kappapp:

build/Kappapp.tar.gz: build/Kappapp
tar -C build -czf $@ Kappapp
rm -r build/Kappapp
rm -rf build/Kappapp

Kappapp.tar.gz: build/Kappapp.tar.gz

Expand Down Expand Up @@ -208,7 +208,7 @@ KappaBin:

build/KappaBin.zip: build/KappaBin
zip -y -r $@ build/KappaBin
rm -r build/KappaBin
rm -rf build/KappaBin

KappaBin.zip: build/KappaBin.zip

Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
(js_of_ocaml-lwt ( = 5.7.0 ))
(js_of_ocaml-ppx ( = 5.7.0 ))
(js_of_ocaml-tyxml ( = 5.7.0 ))
(ppx_inline_test ( = v0.15.1 ))
kappa-binaries
kappa-agents
)
Expand Down
40 changes: 19 additions & 21 deletions gui/dune
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
(library
(name kappa_js_lib)
(modules Common Hooked)
(libraries js_of_ocaml-lwt lwt_react)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags :standard -w +a -open Js_of_ocaml))

(rule
(with-stdout-to
js_of_ocaml_flags
Expand All @@ -18,7 +10,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaSimWorker)
(libraries kappa_js_lib kappa_json_api)
(libraries kappa_webapp_lib kappa_json_api)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -28,7 +20,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_json_api))

Expand All @@ -39,7 +31,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaSaWorker)
(libraries kappa_js_lib kappa_kasa_export)
(libraries kappa_webapp_lib kappa_kasa_export)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -49,7 +41,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_kasa_export))

Expand All @@ -60,7 +52,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaStorWorker)
(libraries kappa_js_lib kappa_cflow)
(libraries kappa_webapp_lib kappa_cflow)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -70,7 +62,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_cflow))

Expand All @@ -81,7 +73,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaMoHaWorker)
(libraries kappa_js_lib kappa_grammar)
(libraries kappa_webapp_lib kappa_grammar)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags :standard -w +a))
Expand All @@ -95,18 +87,17 @@
(modules
:standard
\
Common
Hooked
KaSimWorker
KaSaWorker
KaStorWorker
KaMoHaWorker)
(libraries
js_of_ocaml-tyxml
lwt_react
kappa_js_lib
kappa_webapp_lib
kappa_json_api
kappa_parameters)
kappa_parameters
kappa_webapp_ui)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -118,7 +109,7 @@
-open
Js_of_ocaml_tyxml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_json_api
-open
Expand All @@ -140,4 +131,11 @@
-open
Kappa_logging
-open
Kappa_cflow))
Kappa_cflow
-open
Kappa_webapp_ui
-open
Kappa_webapp_ui
-open
Kappa_webapp_state
))
12 changes: 12 additions & 0 deletions gui/dune_js_of_ocaml_flags.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; Windows build only has access to 4.0.0, where --disable flags don't exist yet in jsoo
; TODO: better distinguish this, as this should depend on jsoo version and not OS

(rule
(with-stdout-to
js_of_ocaml_flags.Unix
(echo "(:standard --disable globaldeadcode --disable deadcode)")))

(rule
(with-stdout-to
js_of_ocaml_flags.Win32
(echo ":standard")))
113 changes: 0 additions & 113 deletions gui/hooked.ml

This file was deleted.

27 changes: 0 additions & 27 deletions gui/hooked.mli

This file was deleted.

File renamed without changes.
17 changes: 15 additions & 2 deletions gui/common.ml → gui/lib/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,22 @@ let async loc (task : unit -> 'a Lwt.t) : unit =
Js_of_ocaml_lwt.Lwt_js_events.async (fun () ->
Lwt.catch task (fun exn ->
let () =
info ~loc:__LOC__ (Js.string (loc ^ Printexc.to_string exn))
warn ~loc:__LOC__
(Js.string
("Async error at " ^ loc ^ ":\n" ^ Printexc.to_string exn))
in
let () = debug ~loc:__LOC__ (Js.string (Printexc.get_backtrace ())) in
let log_trace =
if Printexc.backtrace_status () then (
let trace = Printexc.get_backtrace () in
if String.length trace > 0 then
"Backtrace: " ^ trace
else
"Couldn't get backtrace while backtrace record is enabled, \
might be because of jsoo or react :/"
) else
"Enable backtrace recording to (hopefully?) get backtrace"
in
let () = warn ~loc:__LOC__ (Js.string log_trace) in
Lwt.return_unit))

let guid () : string =
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions gui/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(library
(name kappa_webapp_lib)
(preprocess
(pps
js_of_ocaml-ppx
tyxml-ppx
ppx_inline_test
))
(libraries
js_of_ocaml-lwt
lwt_react
js_of_ocaml-tyxml
ppx_inline_test
kappa_webapp_lib_no_js
kappa_parameters
kappa_kasa_type_interface)
(flags :standard -w +a
-open
Js_of_ocaml
-open
Js_of_ocaml_tyxml
-open
Kappa_kasa_type_interface
-open
Kappa_parameters
))


11 changes: 11 additions & 0 deletions gui/lib/hooked.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module DebugPrint : Kappa_webapp_lib_no_js.Hooked.DebugPrint = struct
let debug_print s =
let () = Common.debug ~loc:__LOC__ s in
()
end

module S = Kappa_webapp_lib_no_js.Hooked.MakeS (DebugPrint)
module E = Kappa_webapp_lib_no_js.Hooked.MakeE (DebugPrint)

type 'a signal = 'a S.t
type 'a event = 'a E.t
6 changes: 6 additions & 0 deletions gui/lib/hooked.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module DebugPrint : Kappa_webapp_lib_no_js.Hooked.DebugPrint
module S : Kappa_webapp_lib_no_js.Hooked.S
module E : Kappa_webapp_lib_no_js.Hooked.E

type 'a signal = 'a S.t
type 'a event = 'a E.t
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e59ed94

Please sign in to comment.