aboutsummaryrefslogtreecommitdiff
path: root/script.it/script.ml
diff options
context:
space:
mode:
Diffstat (limited to 'script.it/script.ml')
-rwxr-xr-xscript.it/script.ml61
1 files changed, 33 insertions, 28 deletions
diff --git a/script.it/script.ml b/script.it/script.ml
index 200d118..a21afa9 100755
--- a/script.it/script.ml
+++ b/script.it/script.ml
@@ -332,10 +332,8 @@ let on_change canva mouse_position timer state =
()
let spawn_worker () =
- try
- Ok (Brr_webworkers.Worker.create (Jstr.v "worker.js"))
- with
- | Jv.Error e -> Error e
+ try Ok (Brr_webworkers.Worker.create (Jstr.v "worker.js"))
+ with Jv.Error e -> Error e
let page_main id =
@@ -351,17 +349,6 @@ let page_main id =
set_sidebar el State.init
end in
-
- let delete_event = E.map (fun () -> `Delete) parameters.delete
- and export_event = E.map (fun () -> `Export) parameters.export
- and angle_event = S.changes parameters.angle
- |> E.map (fun value -> `Angle value)
- and width_event = S.changes parameters.width
- |> E.map (fun value -> `Width value)
- in
-
-
- (*begin match Document.find_el_by_id G.document id with*)
begin match (Jv.is_none id) with
| true -> Console.(error [str "No element with id '%s' found"; id])
| false ->
@@ -369,7 +356,22 @@ let page_main id =
match spawn_worker () with
| Error e -> El.set_children (Jv.Id.of_jv id)
[ El.p El.[txt (Jv.Error.message e)]]
+
| Ok worker ->
+ let delete_event = E.map
+ (fun () -> `Generic (
+ let module Delete = Script_event.Delete in
+ State.E ( Delete.{ worker }
+ , (module Delete: State.Handler with type t = Delete.t)
+ )))
+ parameters.delete
+
+ and export_event = E.map (fun () -> `Export) parameters.export
+ and angle_event = S.changes parameters.angle
+ |> E.map (fun value -> `Angle value)
+ and width_event = S.changes parameters.width
+ |> E.map (fun value -> `Width value)
+ in
let worker_event, worker_send = E.create () in
let my_host = Uri.host @@ Window.location @@ G.window in
@@ -389,24 +391,27 @@ let page_main id =
- Get also the click event for starting to draw
*)
-
let canva_events, mouse_position, canva = canva (Jv.Id.of_jv id) in
-
let canva_events = Note.E.map
(function
- | `MouseDown c -> `MouseDown c
- | `Out c ->
-
+ | `MouseDown c ->
+ let module MouseDown = Script_event.Mouse_down in
`Generic (
State.E
- ( Script_event.Out.{ point = c
- ; worker
- ; timer
- }
- , (module Script_event.Out: State.Handler with type t = Script_event.Out.t)
- )
+ ( MouseDown.{ position = c
+ ; timer
+ }
+ , (module MouseDown: State.Handler with type t = MouseDown.t)))
- )
+ | `Out c ->
+ let module Out = Script_event.Out in
+ `Generic (
+ State.E
+ ( Out.{ point = c
+ ; worker
+ ; timer
+ }
+ , (module Out: State.Handler with type t = Out.t)))
) canva_events in
@@ -419,7 +424,7 @@ let page_main id =
successives events to the initial state *)
let state =
Application.run
- (State.do_action worker timer)
+ (State.do_action worker)
State.init
(E.select
[ worker_event