Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add some froc-dom API

  • Loading branch information...
commit abfb490f3fc44352c9da0f775500b1cc85c7d7e7 1 parent 64480e6
Jake Donham authored
View
6 examples/froc-dom/clicks/clicks.ml
@@ -8,15 +8,15 @@ let onload () =
let clicks = F.count (Fd.clicks (D.document#getElementById "click")) in
let ticks = F.count (Fd.ticks 1000.) in
- Fd.attach_innerHTML
+ Fd.attach_innerHTML_b
(D.document#getElementById "clicks")
(clicks >>= fun c -> F.return (string_of_int c));
- Fd.attach_innerHTML
+ Fd.attach_innerHTML_b
(D.document#getElementById "seconds")
(ticks >>= fun s -> F.return (string_of_int s));
- Fd.attach_innerHTML
+ Fd.attach_innerHTML_b
(D.document#getElementById "difference")
(F.bind2
clicks ticks
View
6 examples/froc-dom/quickhull/quickhull.ml
@@ -205,9 +205,9 @@ let onload () =
let clicks =
F.merge [
- F.map (fun () -> `Stationary) (Fd.clicks (get "stationary"));
- F.map (fun () -> `Bouncing) (Fd.clicks (get "bouncing"));
- F.map (fun () -> `Remove) (Fd.clicks (get "remove"));
+ F.map (fun _ -> `Stationary) (Fd.clicks (get "stationary"));
+ F.map (fun _ -> `Bouncing) (Fd.clicks (get "bouncing"));
+ F.map (fun _ -> `Remove) (Fd.clicks (get "remove"));
] in
let points : (float * float * Fda.color) L.t =
View
41 src/froc-dom/froc_dom.ml
@@ -90,10 +90,6 @@ let mouse_e () =
let mouse_b () = hold (0, 0) (mouse_e ())
-let attach_innerHTML elem b =
- let e = changes b in
- notify_e e (fun s -> elem#_set_innerHTML s)
-
let input_value_e input =
let e, s = make_event () in
let f _ = send s input#_get_value in
@@ -103,13 +99,20 @@ let input_value_e input =
let input_value_b input = hold input#_get_value (input_value_e input)
-let attach_input_value_e i e = notify_e e (fun v -> i#_set_value v)
+let attach_innerHTML_e el e = notify_e e (fun s -> el#_set_innerHTML s)
+let attach_innerHTML_b el b = notify_b b (fun s -> el#_set_innerHTML s)
-let attach_input_value_b i b = attach_input_value_e i (changes b)
+let attach_input_value_e i e = notify_e e (fun v -> i#_set_value v)
+let attach_input_value_b i b = notify_b b (fun v -> i#_set_value v)
let attach_backgroundColor_e el e = notify_e e (fun v -> el#_get_style#_set_backgroundColor v)
+let attach_backgroundColor_b el b = notify_b b (fun v -> el#_get_style#_set_backgroundColor v)
-let attach_backgroundColor_b el b = attach_backgroundColor_e el (changes b)
+let attach_display_e el e = notify_e e (fun v -> el#_get_style#_set_display v)
+let attach_display_b el b = notify_b b (fun v -> el#_get_style#_set_display v)
+
+let attach_fontSize_e el e = notify_e e (fun v -> el#_get_style#_set_fontSize v)
+let attach_fontSize_b el b = notify_b b (fun v -> el#_get_style#_set_fontSize v)
let node_of_result = function
| Value v -> (v :> Dom.node)
@@ -141,9 +144,25 @@ let replaceNode n nb =
old := c in
notify_result_b nb update
-let clicks (elem : #Dom.element) =
+let event name (elem : #Dom.element) =
let e, s = make_event () in
- let f ev = ev#preventDefault; send s () in
- elem#addEventListener "click" f false;
- cleanup (fun () -> elem#removeEventListener "click" f false);
+ let f = send s in
+ elem#addEventListener name f false;
+ cleanup (fun () -> elem#removeEventListener name f false);
e
+
+let mouseEvent name (elem : #Dom.element) =
+ let e, s = make_event () in
+ let f = send s in
+ elem#addEventListener_mouseEvent_ name f false;
+ cleanup (fun () -> elem#removeEventListener_mouseEvent_ name f false);
+ e
+
+let keyEvent name (elem : #Dom.element) =
+ let e, s = make_event () in
+ let f = send s in
+ elem#addEventListener_keyEvent_ name f false;
+ cleanup (fun () -> elem#removeEventListener_keyEvent_ name f false);
+ e
+
+let clicks (elem : #Dom.element) = event "click" elem
View
18 src/froc-dom/froc_dom.mli
@@ -29,17 +29,29 @@ val delay_bb : 'a Froc.behavior -> float Froc.behavior -> 'a Froc.behavior
val mouse_e : unit -> (int * int) Froc.event
val mouse_b : unit -> (int * int) Froc.behavior
-val attach_innerHTML : #Dom.element -> string Froc.behavior -> unit
-
val input_value_e : #Dom.input -> string Froc.event
val input_value_b : #Dom.input -> string Froc.behavior
+
+val attach_innerHTML_e : #Dom.element -> string Froc.event -> unit
+val attach_innerHTML_b : #Dom.element -> string Froc.behavior -> unit
+
val attach_input_value_e : #Dom.input -> string Froc.event -> unit
val attach_input_value_b : #Dom.input -> string Froc.behavior -> unit
val attach_backgroundColor_e : #Dom.element -> string Froc.event -> unit
val attach_backgroundColor_b : #Dom.element -> string Froc.behavior -> unit
+val attach_display_e : #Dom.element -> string Froc.event -> unit
+val attach_display_b : #Dom.element -> string Froc.behavior -> unit
+
+val attach_fontSize_e : #Dom.element -> string Froc.event -> unit
+val attach_fontSize_b : #Dom.element -> string Froc.behavior -> unit
+
val appendChild : #Dom.node -> #Dom.node Froc.behavior -> unit
val replaceNode : #Dom.node -> #Dom.node Froc.behavior -> unit
-val clicks : #Dom.element -> unit Froc.event
+val clicks : #Dom.element -> Dom.event Froc.event
+
+val event : string -> #Dom.element -> Dom.event Froc.event
+val mouseEvent : string -> #Dom.element -> Dom.mouseEvent Froc.event
+val keyEvent : string -> #Dom.element -> Dom.keyEvent Froc.event
Please sign in to comment.
Something went wrong with that request. Please try again.