Skip to content

Commit 98976e4

Browse files
authored
Merge pull request #236 from n-osborne/remove-lwt-ppx
Remove `lwt_ppx` dependency
2 parents e5d8d47 + b711b7b commit 98976e4

13 files changed

+134
-109
lines changed

Makefile.options

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ TEMPLATE_NAME := none.pgocaml
4141

4242
# OCamlfind packages for the server
4343
SERVER_PACKAGES := calendar
44-
SERVER_PPX_PACKAGES := lwt_ppx js_of_ocaml-ppx_deriving_json
44+
SERVER_PPX_PACKAGES := js_of_ocaml-ppx_deriving_json
4545
# OCamlfind packages for the client
4646
CLIENT_PACKAGES := calendar js_of_ocaml js_of_ocaml-lwt
47-
CLIENT_PPX_PACKAGES := js_of_ocaml-ppx lwt_ppx js_of_ocaml-ppx_deriving_json
47+
CLIENT_PPX_PACKAGES := js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json
4848

4949
# Debug package (yes/no): Debugging info in compilation
5050
DEBUG := yes

src/widgets/ot_calendar.eliom

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type button_labels =
3333

3434
[%%client.start]
3535

36+
open Lwt.Syntax
3637
open Js_of_ocaml
3738
open Js_of_ocaml_lwt
3839

@@ -344,7 +345,7 @@ let attach_events ?action ?(click_non_highlighted = false) ?update ~intl ~period
344345
| Some action ->
345346
fun _ r ->
346347
update_classes cal zero d;
347-
let%lwt _ = action y m dom in
348+
let* _ = action y m dom in
348349
Lwt.return_unit
349350
| None -> fun _ r -> update_classes cal zero d; Lwt.return_unit
350351
in
@@ -369,7 +370,7 @@ let attach_events_lwt ?action ?click_non_highlighted ~intl ~period d cal
369370
let f () =
370371
let m = CalendarLib.Date.(month d |> int_of_month)
371372
and y = CalendarLib.Date.year d in
372-
let%lwt highlight = highlight y m in
373+
let* highlight = highlight y m in
373374
attach_events ?action ?click_non_highlighted ~intl ~period d cal highlight;
374375
Lwt.return_unit
375376
in

src/widgets/ot_carousel.eliom

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
*)
3636

3737
open%client Js_of_ocaml
38+
3839
[%%client open Js_of_ocaml_lwt]
3940
[%%shared open Eliom_content.Html]
4041
[%%shared open Eliom_content.Html.F]
42+
[%%shared open Lwt.Syntax]
4143

4244
let%client clX = Ot_swipe.clX
4345
let%client clY = Ot_swipe.clY
@@ -181,7 +183,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
181183
max 1 (truncate (float (width_carousel + 1) /. float width_element))
182184
in
183185
Lwt.async (fun () ->
184-
let%lwt () = Ot_nodeready.nodeready d2' in
186+
let* () = Ot_nodeready.nodeready d2' in
185187
~%set_nb_visible_elements (comp_nb_visible_elements ());
186188
Lwt.return_unit);
187189
let maxi () = ~%maxi - React.S.value ~%nb_visible_elements + 1 in
@@ -294,10 +296,10 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
294296
React.Step.execute step;
295297
set_active ();
296298
Lwt.async (fun () ->
297-
let%lwt () =
299+
let* () =
298300
if move
299301
then
300-
let%lwt _ = Lwt_js_events.transitionend d2' in
302+
let* _ = Lwt_js_events.transitionend d2' in
301303
Lwt.return_unit
302304
else Lwt.return_unit
303305
in
@@ -318,7 +320,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
318320
(fun _ -> ~%set_nb_visible_elements (comp_nb_visible_elements ()))
319321
(if vertical then Ot_size.height else Ot_size.width));
320322
Lwt.async (fun () ->
321-
let%lwt () = Ot_nodeready.nodeready d2' in
323+
let* () = Ot_nodeready.nodeready d2' in
322324
set_position ~%position; add_transition d2'; Lwt.return_unit);
323325
let perform_animation a =
324326
~%set_nb_visible_elements (comp_nb_visible_elements ());
@@ -335,7 +337,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
335337
if not !animation_frame_requested
336338
then (
337339
animation_frame_requested := true;
338-
let%lwt () = Lwt_js_events.request_animation_frame () in
340+
let* () = Lwt_js_events.request_animation_frame () in
339341
animation_frame_requested := false;
340342
(match !action with
341343
| `Move (delta, width_element) ->
@@ -569,25 +571,26 @@ let%client set_default_fail f =
569571
:> exn -> Html_types.div_content Eliom_content.Html.elt)
570572

571573
let%shared generate_content generator =
572-
try%lwt Eliom_shared.Value.local generator ()
573-
with e -> Lwt.return (default_fail e)
574+
Lwt.catch
575+
(fun () -> Eliom_shared.Value.local generator ())
576+
(fun e -> Lwt.return (default_fail e))
574577

575578
(* on the client side we generate the contents of the initially visible page
576579
asynchronously so the tabs will be rendered right away *)
577580
let%client generate_initial_contents ~spinner sleeper gen =
578581
let s = spinner () in
579582
( Lwt.async @@ fun () ->
580-
let%lwt contents = generate_content gen in
583+
let* contents = generate_content gen in
581584
(* wait until DOM elements are created before attempting to replace them *)
582-
let%lwt parent = sleeper in
585+
let* parent = sleeper in
583586
ignore @@ To_dom.of_element parent;
584587
Manip.replaceSelf s contents;
585588
Lwt.return () );
586589
Lwt.return (s, ref @@ None)
587590

588591
(* on the server side we generate all the visible contents right away *)
589592
let%server generate_initial_contents ~spinner:_ _ gen =
590-
let%lwt contents = generate_content gen in
593+
let* contents = generate_content gen in
591594
Lwt.return (contents, ref @@ None)
592595

593596
let%shared make_lazy ?a ?vertical ?(position = 0) ?transition_duration ?inertia
@@ -609,7 +612,7 @@ let%shared make_lazy ?a ?vertical ?(position = 0) ?transition_duration ?inertia
609612
let s = spinner () in
610613
s, ref @@ Some (s, gen)
611614
in
612-
let%lwt contents, spinners_and_generators =
615+
let* contents, spinners_and_generators =
613616
Lwt.map List.split
614617
@@ Lwt_list.map_s (fun x -> x)
615618
@@ List.mapi mk_contents gen_contents
@@ -639,7 +642,7 @@ let%shared make_lazy ?a ?vertical ?(position = 0) ?transition_duration ?inertia
639642
match !spinner_and_generator with
640643
| Some (spinner, gen_content) ->
641644
spinner_and_generator := None;
642-
let%lwt content = generate_content gen_content in
645+
let* content = generate_content gen_content in
643646
Manip.replaceSelf spinner content;
644647
Lwt.return_unit
645648
| None -> Lwt.return ())
@@ -728,7 +731,7 @@ let%shared ribbon ?(a = [])
728731
in
729732
let curleft, set_curleft = React.S.create initial_gap in
730733
Lwt.async (fun () ->
731-
let%lwt () = Ot_nodeready.nodeready container' in
734+
let* () = Ot_nodeready.nodeready container' in
732735
(* Ribbon position: *)
733736
set_containerwidth container'##.offsetWidth;
734737
Ot_noderesize.noderesize (Ot_noderesize.attach container') (fun () ->
@@ -749,7 +752,7 @@ let%shared ribbon ?(a = [])
749752
that runs on window resizing. So we make sure the ribbon code runs
750753
AFTER it has been placed into the fixed container by Ot_sticky. *)
751754
Lwt.async @@ fun () ->
752-
let%lwt _ = Lwt_js.sleep 0.05 in
755+
let* _ = Lwt_js.sleep 0.05 in
753756
set_containerwidth container'##.offsetWidth;
754757
Lwt.return_unit);
755758
(* Changing the position of the ribbon when the carousel position
@@ -880,8 +883,8 @@ let%shared ribbon ?(a = [])
880883
| _ -> ());
881884
Lwt.return_unit);
882885
Lwt.async (fun () ->
883-
let%lwt () = Ot_nodeready.nodeready container' in
884-
let%lwt () = Lwt_js_events.request_animation_frame () in
886+
let* () = Ot_nodeready.nodeready container' in
887+
let* () = Lwt_js_events.request_animation_frame () in
885888
add_transition the_ul';
886889
Eliom_lib.Option.iter add_transition cursor_elt';
887890
Lwt.return_unit);

src/widgets/ot_drawer.eliom

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ open Eliom_content.Html]
2323

2424
[%%shared open Eliom_content.Html.F]
2525
open%client Js_of_ocaml
26+
open%client Lwt.Syntax
2627
[%%client open Js_of_ocaml_lwt]
2728
type%client status = Stopped | Start | Aborted | In_progress
2829

@@ -40,7 +41,7 @@ let%client clY ev =
4041

4142
let%client bind_click_outside bckgrnd elt close =
4243
Lwt.async (fun () ->
43-
let%lwt ev =
44+
let* ev =
4445
Ot_lib.click_outside ~use_capture:true
4546
~inside:(To_dom.of_element bckgrnd)
4647
(To_dom.of_element elt)
@@ -130,7 +131,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
130131
add_class ~%bckgrnd "closing";
131132
Lwt.cancel !(~%touch_thread);
132133
Lwt_js_events.async (fun () ->
133-
let%lwt _ = Lwt_js_events.transitionend (To_dom.of_element ~%d) in
134+
let* _ = Lwt_js_events.transitionend (To_dom.of_element ~%d) in
134135
remove_class ~%bckgrnd "closing";
135136
Eliom_lib.Option.iter (fun f -> f ()) ~%onclose;
136137
Lwt.return_unit)
@@ -148,13 +149,13 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
148149
add_class ~%bckgrnd "opening";
149150
Lwt.cancel !(~%touch_thread);
150151
Lwt.async (fun () ->
151-
let%lwt bind_touch = fst ~%bind_touch in
152+
let* bind_touch = fst ~%bind_touch in
152153
bind_touch (); Lwt.return_unit);
153154
bind_click_outside ~%bckgrnd ~%d ~%close;
154155
Eliom_client.Page_status.onactive ~stop:(fst ~%stop_open_event)
155156
(fun () -> html_ManipClass_add "ot-drawer-open");
156157
Lwt_js_events.async (fun () ->
157-
let%lwt _ = Lwt_js_events.transitionend (To_dom.of_element ~%d) in
158+
let* _ = Lwt_js_events.transitionend (To_dom.of_element ~%d) in
158159
remove_class ~%bckgrnd "opening";
159160
Lwt.return_unit)
160161
: unit -> unit)]
@@ -205,7 +206,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
205206
if not !animation_frame_requested
206207
then (
207208
animation_frame_requested := true;
208-
let%lwt () = Lwt_js_events.request_animation_frame () in
209+
let* () = Lwt_js_events.request_animation_frame () in
209210
animation_frame_requested := false;
210211
(match !action with
211212
| `Move delta ->
@@ -225,7 +226,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
225226
(Js.Unsafe.coerce dr##.style)##.webkitTransform
226227
:= Js.string "";
227228
Lwt.async (fun () ->
228-
let%lwt _ = Lwt_js_events.transitionend dr in
229+
let* _ = Lwt_js_events.transitionend dr in
229230
Manip.Class.remove ~%bckgrnd "ot-swiping";
230231
Lwt.return_unit);
231232
cl ()
@@ -234,7 +235,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
234235
(Js.Unsafe.coerce dr##.style)##.webkitTransform
235236
:= Js.string "";
236237
Lwt.async (fun () ->
237-
let%lwt _ = Lwt_js_events.transitionend dr in
238+
let* _ = Lwt_js_events.transitionend dr in
238239
Manip.Class.remove ~%bckgrnd "ot-swiping";
239240
Lwt.return_unit)
240241
| `Abort ->
@@ -324,36 +325,40 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
324325
status := Start;
325326
startx := clX ev;
326327
starty := clY ev;
327-
let%lwt () = onpan ev a in
328+
let* () = onpan ev a in
328329
(* Lwt.pick and Lwt_js_events.touch*** seem to behave oddly.
329330
This wrapping is an attempt to understand why. *)
330331
let a =
331-
try%lwt Lwt_js_events.touchmoves bckgrnd' onpan with
332-
| Lwt.Canceled -> Lwt.return_unit
333-
| e ->
334-
let s = Printexc.to_string e in
335-
Printf.printf "Ot_drawer>touchmoves>exception: %s\n%!" s;
336-
Lwt.fail e
332+
Lwt.catch
333+
(fun () -> Lwt_js_events.touchmoves bckgrnd' onpan)
334+
(function
335+
| Lwt.Canceled -> Lwt.return_unit
336+
| e ->
337+
let s = Printexc.to_string e in
338+
Printf.printf "Ot_drawer>touchmoves>exception: %s\n%!" s;
339+
Lwt.fail e)
337340
and b =
338-
try%lwt
339-
let%lwt ev = Lwt_js_events.touchend bckgrnd' in
340-
onpanend ev ()
341-
with
342-
| Lwt.Canceled -> Lwt.return_unit
343-
| e ->
344-
let s = Printexc.to_string e in
345-
Printf.printf "Ot_drawer>touchend>exception: %s\n%!" s;
346-
Lwt.fail e
341+
Lwt.catch
342+
(fun () ->
343+
let* ev = Lwt_js_events.touchend bckgrnd' in
344+
onpanend ev ())
345+
(function
346+
| Lwt.Canceled -> Lwt.return_unit
347+
| e ->
348+
let s = Printexc.to_string e in
349+
Printf.printf "Ot_drawer>touchend>exception: %s\n%!" s;
350+
Lwt.fail e)
347351
and c =
348-
try%lwt
349-
let%lwt ev = Lwt_js_events.touchcancel bckgrnd' in
350-
onpanend ev ()
351-
with
352-
| Lwt.Canceled -> Lwt.return_unit
353-
| e ->
354-
let s = Printexc.to_string e in
355-
Printf.printf "Ot_drawer>touchcancel>exception: %s\n%!" s;
356-
Lwt.fail e
352+
Lwt.catch
353+
(fun () ->
354+
let* ev = Lwt_js_events.touchcancel bckgrnd' in
355+
onpanend ev ())
356+
(function
357+
| Lwt.Canceled -> Lwt.return_unit
358+
| e ->
359+
let s = Printexc.to_string e in
360+
Printf.printf "Ot_drawer>touchcancel>exception: %s\n%!" s;
361+
Lwt.fail e)
357362
in
358363
Lwt.pick [a; b; c]
359364
in

src/widgets/ot_lib.eliom

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* along with this program; if not, write to the Free Software
2020
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2121
*)
22-
open Js_of_ocaml]
22+
open Js_of_ocaml
23+
open Lwt.Syntax]
2324

2425
[%%client open Js_of_ocaml_lwt]
2526

@@ -46,7 +47,7 @@ let%client window_scrolls ?(ios_html_scroll_hack = false) ?use_capture handler =
4647
if ios_html_scroll_hack
4748
then
4849
let rec loop () =
49-
let%lwt e =
50+
let* e =
5051
Lwt.pick
5152
(List.map
5253
(* We listen to several elements because scroll events are
@@ -59,12 +60,15 @@ let%client window_scrolls ?(ios_html_scroll_hack = false) ?use_capture handler =
5960
in
6061
let continue = ref true in
6162
let w =
62-
try%lwt fst (Lwt.task ())
63-
with Lwt.Canceled ->
64-
continue := false;
65-
Lwt.return_unit
63+
Lwt.catch
64+
(fun () -> fst (Lwt.task ()))
65+
(function
66+
| Lwt.Canceled ->
67+
continue := false;
68+
Lwt.return_unit
69+
| exc -> Lwt.reraise exc)
6670
in
67-
let%lwt () = handler e w in
71+
let* () = handler e w in
6872
if !continue then loop () else Lwt.return_unit
6973
in
7074
loop ()
@@ -91,7 +95,7 @@ let%client rec in_ancestors ~elt ~ancestor =
9195
let%client rec click_outside ?use_capture
9296
?(inside = (Dom_html.document##.body :> Dom_html.element Js.t)) elt
9397
=
94-
let%lwt ev = Lwt_js_events.click ?use_capture inside in
98+
let* ev = Lwt_js_events.click ?use_capture inside in
9599
Js.Opt.case ev##.target
96100
(fun () -> click_outside ?use_capture elt)
97101
(fun target ->

0 commit comments

Comments
 (0)