@@ -23,8 +23,8 @@ And wasm-bindgen: `cargo install wasm-bindgen-cli`
23
23
### The theoretical minimum
24
24
To start, clone [ This quickstart repo] ( https://github.com/David-OConnor/seed-quickstart ) ,
25
25
run ` build.sh ` or ` build.ps1 ` in a terminal, then start a dev server that supports WASM.
26
- For example, with [ Python] ( https://www.python.org/downloads/ ) installed, run ` python server .py ` .
27
- (Linux users may need to run ` python3 server .py ` .)
26
+ For example, with [ Python] ( https://www.python.org/downloads/ ) installed, run ` python serve .py ` .
27
+ (Linux users may need to run ` python3 serve .py ` .)
28
28
Once you change your package name, you'll
29
29
need to tweak the html file and build script, as described below.
30
30
@@ -170,13 +170,13 @@ fn view(model: Model) -> El<Msg> {
170
170
// When passing numerical values to style!, "px" is implied.
171
171
" border" => " 2px solid #004422" ; " padding" => 20
172
172
},
173
- // We can use normal Rust code and comments in the view.
174
- h3! [ format! (" {} {}{} so far" , model . count, model . what_we_count, plural ) ],
175
- button! [ simple_ev (" click" , Msg :: Increment ), " +" ],
176
- button! [ simple_ev (" click" , Msg :: Decrement ), " -" ],
173
+ // We can use normal Rust code and comments in the view.
174
+ h3! [ format! (" {} {}{} so far" , model . count, model . what_we_count, plural ) ],
175
+ button! [ simple_ev (" click" , Msg :: Increment ), " +" ],
176
+ button! [ simple_ev (" click" , Msg :: Decrement ), " -" ],
177
177
178
- // Optionally-displaying an element
179
- if model . count >= 10 { h2! [ style! {" padding" => 50 }, " Nice!" ] } else { seed :: empty () }
178
+ // Optionally-displaying an element
179
+ if model . count >= 10 { h2! [ style! {" padding" => 50 }, " Nice!" ] } else { seed :: empty () }
180
180
181
181
],
182
182
success_level (model . count), // Incorporating a separate component
@@ -212,8 +212,8 @@ The Quickstart repo includes these, but you'll still need to do the rename. You
212
212
` ./build.sh ` or ` .\build.ps1 `
213
213
214
214
For development, you can view your app using a shimmed Python dev server described above.
215
- (Set up [ this mime-type shim] ( https://github.com/David-OConnor/seed-quickstart/blob/master/server .py )
216
- from the quickstart repo, and run ` python server .py ` ).
215
+ (Set up [ this mime-type shim] ( https://github.com/David-OConnor/seed-quickstart/blob/master/serve .py )
216
+ from the quickstart repo, and run ` python serve .py ` ).
217
217
218
218
For details, reference [ the wasm-bindgen documention] ( https://rustwasm.github.io/wasm-bindgen/whirlwind-tour/basic-usage.html ) .
219
219
In the future, I'd like the build script and commands above to be replaced by [ wasm-pack] ( https://github.com/rustwasm/wasm-pack ) .
@@ -468,7 +468,7 @@ extern crate seed;
468
468
469
469
div! []
470
470
```
471
- These macros accept any combination (0 or 1 per) of the following parameters:
471
+ These macros accept any combination of the following parameters:
472
472
- One [ Attrs] ( https://docs.rs/seed/0.1.6/seed/dom_types/struct.Attrs.html ) struct
473
473
- One [ Style] ( https://docs.rs/seed/0.1.6/seed/dom_types/struct.Style.html ) struct
474
474
- One or more [ Listener] ( https://docs.rs/seed/0.1.6/seed/dom_types/struct.Listener.html ) structs, which handle events
@@ -525,10 +525,10 @@ the same one more than once:
525
525
526
526
Setting an InputElement's ` checked ` property is done through normal attributes:
527
527
``` rust
528
- input! [ attrs! {" type" => " checkbox" ; " checked" => true ]
528
+ input! [ attrs! {" type" => " checkbox" ; " checked" => true } ]
529
529
```
530
530
531
- To edit Attrs or Styles you've created, you can edit their .vals HashMap. To add
531
+ To change Attrs or Styles you've created, edit their .vals HashMap. To add
532
532
a new part to them, use their .add method:
533
533
``` rust
534
534
let mut attributes = attrs! {};
@@ -559,6 +559,19 @@ fn view(model: Model) -> El<Msg> {
559
559
}
560
560
```
561
561
562
+ We can combine Attrs and Style instances using their ` merge ` methods, which take
563
+ an &Attrs and &Style respectively. This can be used to compose styles from reusable parts.
564
+ Example:
565
+ ``` rust
566
+ let base_style = ! style {" color" => " lavender" };
567
+
568
+ div! [
569
+ h1! [ & base_style . merge (& style! {" grid-row" => " 1 / 2" }) " First row" ],
570
+ h1! [ & base_style . merge (& style! {" grid-row" => " 2 / 3" }) " Second row" ],
571
+ ]
572
+ ```
573
+
574
+
562
575
Overall: we leverage of Rust's strict type system to flexibly-create the view
563
576
using normal Rust code.
564
577
@@ -885,10 +898,6 @@ function run() {
885
898
```
886
899
Note that you don't need to pass your Msg enum; it's inferred from the update function.
887
900
888
- ### Comments in the view
889
- The Element-creation macros used to create views are normal Rust code, you can
890
- use comments in them normally: either on their own line, or in line.
891
-
892
901
893
902
### Logging in the web browser
894
903
To output to the web browser's console (ie ` console.log() ` in JS), use ` web_sys::console_log1 ` ,
@@ -942,11 +951,12 @@ let data = serde_json::from_str(&loaded_serialized).unwrap();
942
951
943
952
```
944
953
945
- ### Display markdown
954
+ ### Display markdown and raw HTML
946
955
Seed supports creating elements from markdown text, using [ pulldown-cmark] ( https://github.com/raphlinus/pulldown-cmark )
947
956
internally. Use the [ El::from_markdown()] ( https://docs.rs/seed/0.1.6/seed/dom_types/struct.El.html#method.from_markdown )
948
957
method to create an element that accepts a markdown &str as its only parameter, and displays
949
- it normally as html.
958
+ it normally as html. Note that it does not support syntax highlighting. You can render raw HTML with ` El::from_html(html) ` , where ` html ` is a
959
+ &str of HTML.
950
960
951
961
Example:
952
962
``` rust
@@ -958,13 +968,26 @@ fn view(model: Model) -> El<Msg> {
958
968
959
969
Let's set the existence-of-God issue aside for a later volume,
960
970
and just [learn to code](https://play.rust-lang.org/).
961
- " ;
971
+ "
972
+ ;
973
+
974
+ let html =
975
+ "
976
+ <div>
977
+ <p>It is a truth universally acknowledged, that a single man in
978
+ possession of a good fortune, must be in want of a good time./p>
979
+ </div>
980
+ "
981
+ ;
962
982
963
983
div! [
964
984
El :: from_markdown (markdown )
985
+ El :: from_html (html )
965
986
]
966
987
}
967
988
989
+
990
+
968
991
```
969
992
970
993
### Building a release version
@@ -1016,8 +1039,8 @@ of your familiarity with Rust.
1016
1039
1017
1040
- Complete documentation that always matches the current version. Getting examples working, and
1018
1041
starting a project should be painless, and require nothing beyond this guide.
1019
-
1020
- - An API that's easy to read, write, and understand .
1042
+
1043
+ - Concise, flexibilty vew syntax that's easy to read and write .
1021
1044
1022
1045
1023
1046
### A note on view syntax
@@ -1081,10 +1104,10 @@ You may choose
1081
1104
this approach over Elm if you're already comfortable with Rust, want the performance
1082
1105
benefits, or don't want to code business logic in a purely-functional langauge.
1083
1106
1084
- Compared to React, for example , you may appreciate the consistency of how to write apps:
1107
+ Compared with React, you may appreciate the consistency of how to write apps:
1085
1108
There's no distinction between logic and display code; no restrictions on comments;
1086
1109
no distinction between components and normal functions. The API is
1087
- flexible, and avoids the OOP boilerplate.
1110
+ flexible, and avoids OOP boilerplate.
1088
1111
1089
1112
I also hope that config, building, and dependency-management is cleaner with Cargo and
1090
1113
wasm-bindgen than with npm.
0 commit comments