1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
open Js_of_ocaml
class type configuration = object
method auto : bool Js.prop
method el : Dom_html.divElement Js.t Js.prop
method value : int Js.prop
method format : Js.js_string Js.t Js.prop
method theme : Js.js_string Js.t Js.prop
method animation : Js.js_string Js.t
end
class type odometer = object
method update : int -> unit Js.meth
end
type configuraton = {
auto : bool option ;
element : Dom_html.divElement Js.t ;
value : int ;
format : string option ;
theme : string option ;
animation : string option ;
}
let from_config config =
let configuration : configuration Js.t = Js.Unsafe.obj [||] in
configuration##.el := config.element ;
configuration##.value := config.value ;
begin match config.format with
| None -> ()
| Some format -> configuration##.format := Js.string format
end ;
begin match config.auto with
| None -> ()
| Some auto -> configuration##.auto := auto
end ;
begin match config.theme with
| None -> ()
| Some theme -> configuration##.theme := Js.string theme
end
let odometer_with_config config =
let configuration = from_config config in
let odometer_ctsr = Js.Unsafe.global##._Odometer in
(Js.Unsafe.new_obj odometer_ctsr
[| Js.Unsafe.inject configuration |] : odometer Js.t)
let odometer el =
let configuration : configuration Js.t = Js.Unsafe.obj [||] in
configuration##.el := el ;
configuration##.value := 0 ;
configuration##.format := Js.string "d" ;
let odometer_ctsr = Js.Unsafe.global##._Odometer in
(Js.Unsafe.new_obj odometer_ctsr
[| Js.Unsafe.inject configuration |] : odometer Js.t)
let update od value =
od##(update value)