Skip to content

Commit

Permalink
improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rizo committed Apr 8, 2024
1 parent 77da337 commit acbdc57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

```ocaml
open Helix
open Stdweb
let counter () =
let count = Signal.make 0 in
Expand All @@ -34,26 +33,25 @@ let counter () =
div []
[
button
[ on_click (fun _ -> Signal.update (fun n -> n + 1) count) ]
[ on_click (fun () -> Signal.update (fun n -> n + 1) count) ]
[ text "+" ];
button
[ on_click (fun _ -> Signal.update (fun n -> n - 1) count) ]
[ on_click (fun () -> Signal.update (fun n -> n - 1) count) ]
[ text "-" ];
button [ on_click (fun () -> Signal.emit 0 count) ] [ text "Reset" ];
div
[
style_list [ ("font-size", "32px") ];
bind
(fun n ->
if n < 0 then style_list [ ("color", "red") ]
else style_list [ ("color", "blue") ])
(fun n -> style_list [ ("color", if n < 0 then "red" else "blue") ])
count;
]
[ show (fun n -> text (string_of_int n)) count ];
];
]
let () =
match Dom.Document.get_element_by_id "root" with
match Stdweb.Dom.Document.get_element_by_id "root" with
| Some root -> Html.mount root (counter ())
| None -> failwith "No #root element found"
```
Expand Down
11 changes: 5 additions & 6 deletions examples/readme/Readme.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Helix
open Stdweb

let counter () =
let count = Signal.make 0 in
Expand All @@ -12,18 +11,18 @@ let counter () =
div []
[
button
[ on_click (fun _ -> Signal.update (fun n -> n + 1) count) ]
[ on_click (fun () -> Signal.update (fun n -> n + 1) count) ]
[ text "+" ];
button
[ on_click (fun _ -> Signal.update (fun n -> n - 1) count) ]
[ on_click (fun () -> Signal.update (fun n -> n - 1) count) ]
[ text "-" ];
button [ on_click (fun () -> Signal.emit 0 count) ] [ text "Reset" ];
div
[
style_list [ ("font-size", "32px") ];
bind
(fun n ->
if n < 0 then style_list [ ("color", "red") ]
else style_list [ ("color", "blue") ]
style_list [ ("color", if n < 0 then "red" else "blue") ]
)
count;
]
Expand All @@ -32,6 +31,6 @@ let counter () =
]

let () =
match Dom.Document.get_element_by_id "root" with
match Stdweb.Dom.Document.get_element_by_id "root" with
| Some root -> Html.mount root (counter ())
| None -> failwith "No #root element found"

0 comments on commit acbdc57

Please sign in to comment.