diff options
Diffstat (limited to 'script.it/script.ml')
-rwxr-xr-x | script.it/script.ml | 103 |
1 files changed, 71 insertions, 32 deletions
diff --git a/script.it/script.ml b/script.it/script.ml index a21afa9..29bf2c9 100755 --- a/script.it/script.ml +++ b/script.it/script.ml @@ -87,7 +87,7 @@ type 'a param_events = ; angle : float S.t ; export : unit E.t ; delete : unit E.t - ; rendering : ([> State.render_event] as 'a) E.t + ; rendering : State.events E.t } type slider = @@ -160,11 +160,22 @@ let set_sidebar Ev.change (fun _ -> let raw_value = El.prop El.Prop.value render |> Jstr.to_int in - match raw_value with - | Some 1 -> `Rendering `Fill - | Some 2 -> `Rendering `Line - | Some 3 -> `Rendering `Ductus - | _ -> `Rendering `Fill + let render_type = match raw_value with + | Some 1 -> `Fill + | Some 2 -> `Line + | Some 3 -> `Ductus + | _ -> `Fill in + + let module M = struct + type t = Layer.Paths.printer + let update t state = { state with State.rendering = t } + end + in + + State.E + ( render_type + , (module M: State.Handler with type t = Layer.Paths.printer )) + ) rendering' in let () = @@ -358,22 +369,52 @@ let page_main id = [ El.p El.[txt (Jv.Error.message e)]] | Ok worker -> + + let worker_event, worker_send = E.create () in + 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) - ))) + (fun () -> + 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 export_event = + E.map (fun () -> + let module Export = Script_event.Export in + State.E + ( () + , (module Export: State.Handler with type t = Export.t ))) + parameters.export and angle_event = S.changes parameters.angle - |> E.map (fun value -> `Angle value) + |> E.map (fun value -> + let module Property = Script_event.Property in + State.E + ( Property.{ value ; worker ; prop = `Angle } + , (module Property: State.Handler with type t = Property.t ))) + and width_event = S.changes parameters.width - |> E.map (fun value -> `Width value) + |> E.map (fun value -> + let module Property = Script_event.Property in + State.E + ( Property.{ value ; worker ; prop = `Width } + , (module Property: State.Handler with type t = Property.t ))) + and worker_event = Note.E.filter_map + (function + | `Other t -> + Console.(log [t]); + None + | `Complete outline -> + let module Complete_path = Script_event.Complete_path in + Some ( + State.E + ( outline + , (module Complete_path: State.Handler with type t = Complete_path.t )))) + + worker_event in - let worker_event, worker_send = E.create () in let my_host = Uri.host @@ Window.location @@ G.window in if (Hashtbl.hash my_host) = Blog.Hash_host.expected_host then ( let target = Brr_webworkers.Worker.as_target worker in @@ -396,35 +437,33 @@ let page_main id = (function | `MouseDown c -> let module MouseDown = Script_event.Mouse_down in - `Generic ( - State.E - ( MouseDown.{ position = c - ; timer - } - , (module MouseDown: State.Handler with type t = MouseDown.t))) + State.E + ( 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))) - + let module Click = Script_event.Click in + State.E + ( Click.{ point = c ; worker; timer } + , (module Click: State.Handler with type t = Click.t )) ) canva_events in let tick_event = S.sample_filter mouse_position ~on:tick - (fun pos f -> Option.map (fun p -> `Point (f, p)) pos ) in + (fun pos f -> + let module Tick = Script_event.Tick in + Option.map (fun p -> + State.E + ( (f, p) + , (module Tick: State.Handler with type t = Tick.t ))) + pos ) in (* The first evaluation is the state. Which is the result of all the successives events to the initial state *) let state = Application.run - (State.do_action worker) + State.do_action State.init (E.select [ worker_event |