use gadts for event, clean repo

This commit is contained in:
zapashcanon 2022-04-08 22:43:31 +02:00
parent d9f25e4d8d
commit f4ab3e17ad
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1
8 changed files with 118 additions and 126 deletions

View file

@ -1,15 +1,5 @@
type t = Jv.t
module Event = struct
let to_brr s = s |> Jstr.v |> Brr.Ev.Type.create
let click = to_brr "click"
let moveend = to_brr "moveend"
let zoomend = to_brr "zoomend"
end
let of_jv_t = Fun.id
let to_jv_t = Fun.id
@ -34,9 +24,11 @@ let set_view latlng ?zoom map =
let as_target map = Brr.Ev.target_of_jv map
let on ~event ~handler map =
let name = Brr.Ev.Type.name event |> Jv.of_jstr in
ignore @@ Jv.call map "on" [| name; Jv.repr handler |]
let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> t -> unit =
fun event handler map ->
let name = Event.sub_to_string event in
let handler v = handler @@ Event.of_jv_t event v in
ignore @@ Jv.call map "on" [| Jv.of_string name; Jv.repr handler |]
let get_center map = Latlng.of_jv_t @@ Jv.call map "getCenter" [||]