Skip to content

Commit c7cb7a9

Browse files
v0.18~preview.130.26+1192
1 parent cc9ff10 commit c7cb7a9

File tree

187 files changed

+2542
-1271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+2542
-1271
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2024 Jane Street Group, LLC <opensource-contacts@janestreet.com>
3+
Copyright (c) 2024--2025 Jane Street Group, LLC <opensource-contacts@janestreet.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

accordion/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ let component graph =
8383

8484
let () =
8585
Async_js.init ();
86-
Bonsai_web.Start.start component
86+
Bonsai_web.Start.start component ~enable_bonsai_telemetry:Enabled
8787
;;

animation/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ let component graph =
6767
]
6868
;;
6969

70-
let () = Bonsai_web.Start.start component
70+
let () = Bonsai_web.Start.start component ~enable_bonsai_telemetry:Enabled

beforeunload/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ let component _graph =
1111
[ Vdom.Node.text "attempting to leave this page will show a warning" ])
1212
;;
1313

14-
let () = Bonsai_web.Start.start component
14+
let () = Bonsai_web.Start.start component ~enable_bonsai_telemetry:Enabled

bonsai_examples.opam

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ depends: [
2727
"virtual_dom"
2828
"cohttp" {>= "2.5.6"}
2929
"cohttp-async" {>= "2.5.7" & < "3.0.0" | >= "5.1.1" & < "6.0.0"}
30-
"dune" {>= "3.11.0"}
31-
"js_of_ocaml" {>= "5.1.1" & < "5.7.0"}
32-
"js_of_ocaml-ppx" {>= "5.1.1" & < "5.7.0"}
30+
"dune" {>= "3.17.0"}
31+
"js_of_ocaml" {>= "6.0.0"}
32+
"js_of_ocaml-ppx" {>= "6.0.0"}
3333
"uri" {>= "3.0.0"}
3434
]
3535
available: arch != "arm32" & arch != "x86_32"

bonsai_guide_code/best_practices_examples.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ let compute_magic_number a b = a * b
88
let a_typical_function (input : int Bonsai.t) graph =
99
(* Declare your state *)
1010
let num_input_changes, incr_num_input_changes =
11-
Bonsai.state_machine0
11+
Bonsai.state_machine
1212
~default_model:0
1313
~apply_action:(fun _ model () -> model + 1)
1414
graph
1515
in
1616
let (logs : string Bonsai.t), (write_log_line : (string -> unit Effect.t) Bonsai.t) =
17-
Bonsai.state_machine0
17+
Bonsai.state_machine
1818
~default_model:""
1919
~apply_action:(fun _ logs new_log_line ->
2020
match logs with

bonsai_guide_code/bonsai_types.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ module Bonsai = Bonsai.Cont
33

44
let assoc = Bonsai.assoc
55

6-
let state_machine0 ~default_model ~apply_action graph =
7-
Bonsai.state_machine0 ~default_model ~apply_action graph
6+
let state_machine ~default_model ~apply_action graph =
7+
Bonsai.state_machine ~default_model ~apply_action graph
88
;;
99

1010
let peek = Bonsai.peek
1111

1212
module Url_var = Bonsai_web_ui_url_var
1313

1414
let mirror = Bonsai_extra.mirror
15+
16+
module Apply_action_context = Bonsai.Apply_action_context

bonsai_guide_code/bonsai_types.mli

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ module Url_var := Bonsai_web_ui_url_var
1010
(* $MDX part-begin=assoc *)
1111
val assoc
1212
: ?here:Stdlib.Lexing.position
13-
-> ('k, 'cmp) Bonsai.comparator
13+
-> ('k, 'cmp) Comparator.Module.t
1414
-> ('k, 'v, 'cmp) Map.t Bonsai.t
1515
-> f:('k Bonsai.t -> 'v Bonsai.t -> Bonsai.graph -> 'result Bonsai.t)
1616
-> Bonsai.graph
1717
-> ('k, 'result, 'cmp) Map.t Bonsai.t
1818
(* $MDX part-end *)
1919

20-
(* $MDX part-begin=state_machine0 *)
21-
val state_machine0
20+
(* $MDX part-begin=state_machine *)
21+
val state_machine
2222
: default_model:'model
2323
-> apply_action:
2424
(('action, unit) Bonsai.Apply_action_context.t -> 'model -> 'action -> 'model)
@@ -80,32 +80,32 @@ module Url_var : sig
8080
end
8181

8282
(* $MDX part-begin=mirror *)
83-
84-
(** [mirror] is used to reflect state back and forth between locations.
85-
Frequently this will be used to back up a components model in a more
86-
persistent form of storage, such as the URL, or local-storage.
87-
88-
The gist of this combinator is that if you have two states that you'd
89-
like to be synchronized, you can feed the "current value" and "set
90-
value" functions for both states into [mirror] and they'll
91-
automatically be kept up to date. Either of these can be backed by any
92-
kind of structure, but there are some important differences in their
93-
symmetry.
94-
95-
When the component is first loaded, [store] has priority, so if the
96-
values are different, [store] wins, and [interactive] has its value
97-
"set". From that point on, if either incoming value changes, the
98-
opposite setter is called. In the case that both [store] and
99-
[interactive] change at the same time, the tie is broken in favor of
100-
[interactive], and [store_set] is called. *)
10183
val mirror
10284
: ?sexp_of_model:('m -> Sexp.t)
10385
-> equal:('m -> 'm -> bool)
10486
-> store_set:('m -> unit Effect.t) Bonsai.t
10587
-> store_value:'m Bonsai.t
10688
-> interactive_set:('m -> unit Effect.t) Bonsai.t
10789
-> interactive_value:'m Bonsai.t
108-
-> unit
10990
-> Bonsai.graph
110-
-> unit Bonsai.t
91+
-> unit
92+
(* $MDX part-end *)
93+
94+
(* $MDX part-begin=apply_action_context *)
95+
module Apply_action_context : sig
96+
(** A value with the type [('action, 'response) Apply_action_context.t] is provided to
97+
all state-machine's [apply_action] functions. It can be used to do a variety of
98+
things that are only legal inside of [apply_action]:
99+
1. Access the application time source directly. This is most likely useful to read
100+
the current time or sleep for some time span
101+
2. "inject" a value corresponding to the state-machine's action type into an effect
102+
that can be scheduled.
103+
3. Directly schedule effects. *)
104+
105+
type ('action, 'response) t
106+
107+
val inject : ('action, 'response) t -> 'action -> 'response Effect.t
108+
val schedule_event : _ t -> unit Effect.t -> unit
109+
val time_source : _ t -> Bonsai.Time_source.t
110+
end
111111
(* $MDX part-end *)

bonsai_guide_code/control_flow_examples.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let maybe_show_naive show graph =
1010
let counter = counter ~step:(return 1) graph in
1111
let%arr counter and show in
1212
match show with
13-
| false -> Vdom.Node.none_deprecated [@alert "-deprecated"]
13+
| false -> Vdom.Node.none
1414
| true -> counter
1515
;;
1616

@@ -34,7 +34,7 @@ let () = Util.run (show_control maybe_show_naive) ~id:"maybe_show_naive"
3434
let maybe_show show graph =
3535
let counter = counter ~step:(return 1) graph in
3636
match%sub show with
37-
| false -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
37+
| false -> Bonsai.return Vdom.Node.none
3838
| true -> counter
3939
;;
4040

@@ -56,7 +56,7 @@ let maybe_show_2 show graph =
5656
match%sub show with
5757
| `Count_by_1 -> counter ~step:(return 1) graph
5858
| `Count_by_2 -> counter ~step:(return 2) graph
59-
| `No -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
59+
| `No -> Bonsai.return Vdom.Node.none
6060
;;
6161

6262
(* $MDX part-end *)
@@ -84,7 +84,7 @@ let () = Util.run (show_control_2 maybe_show_2) ~id:"maybe_show_2"
8484
let maybe_show_var show graph =
8585
match%sub show with
8686
| `Count_by step -> counter ~step graph
87-
| `No -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
87+
| `No -> Bonsai.return Vdom.Node.none
8888
;;
8989

9090
(* $MDX part-end *)
@@ -94,7 +94,7 @@ let maybe_show_var_guard show graph =
9494
| `Count_by step when Int.equal step 1 -> counter ~step graph
9595
| `Count_by step when Int.equal step 4 -> counter ~step graph
9696
| `Count_by step -> counter ~step graph
97-
| `No -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
97+
| `No -> Bonsai.return Vdom.Node.none
9898
;;
9999

100100
(* $MDX part-end *)
@@ -108,7 +108,7 @@ let maybe_show_var_scope_model show graph =
108108
~on:step
109109
~for_:(fun graph -> counter ~step graph)
110110
graph
111-
| `No -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
111+
| `No -> Bonsai.return Vdom.Node.none
112112
;;
113113

114114
(* $MDX part-end *)
@@ -150,7 +150,7 @@ let maybe_show_dynamic_count show graph =
150150
match%sub show with
151151
| `Count_by_1 -> counter ~step:(return 1) graph
152152
| `Count_by_2 -> counter ~step:(return 2) graph
153-
| `No -> Bonsai.return (Vdom.Node.none_deprecated [@alert "-deprecated"])
153+
| `No -> Bonsai.return Vdom.Node.none
154154
;;
155155

156156
(* $MDX part-end *)
@@ -183,6 +183,7 @@ let multiple_counters (input : unit Int.Map.t Bonsai.t) graph =
183183
input
184184
~f:(fun key (_ : unit Bonsai.t) graph ->
185185
let%arr key
186+
(* [counter_ui] is like [counter] but only returns the view. *)
186187
and counter = State_examples.counter_ui graph in
187188
Vdom.Node.tr
188189
[ Vdom.Node.td [ Vdom.Node.textf "counter #%d:" key ]

bonsai_guide_code/css_examples.ml

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ open! Bonsai.Let_syntax
66
let view =
77
Vdom.Node.div
88
~attrs:
9-
[ [%css
10-
{|
11-
background-color: tomato;
12-
min-width: 2rem;
13-
min-height: 2rem;
14-
|}]
9+
[ {%css|
10+
background-color: tomato;
11+
min-width: 2rem;
12+
min-height: 2rem;
13+
|}
1514
]
1615
[ Vdom.Node.text "Very Red Background" ]
1716
;;
@@ -23,7 +22,7 @@ let () = Util.run_vdom view ~id:"ppx_css_inline"
2322
(* $MDX part-begin=ppx_css_inline_interpol *)
2423
let box_with_border (color : Css_gen.Color.t) (width : Css_gen.Length.t) =
2524
Vdom.Node.div
26-
~attrs:[ [%css {|border: %{width#Css_gen.Length} solid %{color#Css_gen.Color};|}] ]
25+
~attrs:[ {%css|border: %{width#Css_gen.Length} solid %{color#Css_gen.Color};|} ]
2726
[ Vdom.Node.text "Nice Borders!" ]
2827
;;
2928

@@ -38,21 +37,20 @@ let hoverable_blocks =
3837
let block =
3938
Vdom.Node.div
4039
~attrs:
41-
[ [%css
42-
{|
43-
background-color: green;
44-
min-width: 2rem;
45-
min-height: 2rem;
46-
border: 1px solid black;
47-
48-
&:hover {
49-
background-color: tomato;
50-
}
51-
52-
&:not(:nth-child(odd)):hover {
53-
background-color: purple;
54-
}
55-
|}]
40+
[ {%css|
41+
background-color: green;
42+
min-width: 2rem;
43+
min-height: 2rem;
44+
border: 1px solid black;
45+
46+
&:hover {
47+
background-color: tomato;
48+
}
49+
50+
&:not(:nth-child(odd)):hover {
51+
background-color: purple;
52+
}
53+
|}
5654
]
5755
[ Vdom.Node.text "Hoverable" ]
5856
in
@@ -66,9 +64,9 @@ let () = Util.run_vdom hoverable_blocks ~id:"ppx_css_inline_nesting"
6664
(* $MDX part-begin=ppx_css_inline_multiple *)
6765
let multiple_ppx_css =
6866
Vdom.Node.div
69-
~attrs:[ [%css {|color: red;|}] ]
67+
~attrs:[ {%css|color: red;|} ]
7068
[ Vdom.Node.text "Foo"
71-
; Vdom.Node.div ~attrs:[ [%css {|color: blue;|}] ] [ Vdom.Node.text "Bar" ]
69+
; Vdom.Node.div ~attrs:[ {%css|color: blue;|} ] [ Vdom.Node.text "Bar" ]
7270
]
7371
;;
7472

@@ -98,7 +96,7 @@ module Style =
9896
font-size: 20px;
9997
}
10098
}
101-
|}]
99+
|}]
102100

103101
let stylesheet_demo = Vdom.Node.div ~attrs:[ Style.container ] [ Vdom.Node.text "Hello" ]
104102

@@ -124,7 +122,7 @@ let stylesheet_interpol small_bg large_bg =
124122
background-color: %{large_bg#Css_gen.Color};
125123
}
126124
}
127-
|}]
125+
|}]
128126
in
129127
Vdom.Node.div ~attrs:[ Style.container ] [ Vdom.Node.text "Hello" ]
130128
;;
@@ -154,7 +152,7 @@ module _ = struct
154152
background-color: var(--large-bg);
155153
}
156154
}
157-
|}]
155+
|}]
158156

159157
let stylesheet_vars =
160158
Vdom.Node.div

0 commit comments

Comments
 (0)