Skip to content

Commit c7599c5

Browse files
Tidy up the documentation. (#2404)
- fix a number of typos/grammatical errors - also includes some stylistic changes
1 parent 4580d94 commit c7599c5

14 files changed

Lines changed: 88 additions & 68 deletions

File tree

website/docs/advanced-topics/how-it-works.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ Using the `html!` macro can feel pretty magic, but it has nothing to hide. If yo
2323
how it works, try expanding the `html!` macro calls in your program. There's a useful command called
2424
`cargo expand` which allows you to see the expansion of Rust macros. `cargo expand` isn't shipped with
2525
`cargo` by default so you'll need to install it with `cargo install cargo-expand` if you haven't
26-
already.
26+
already. [Rust-Analyzer](https://rust-analyzer.github.io/) also provides a mechanism for
27+
[obtaining macro output from within an IDE](https://rust-analyzer.github.io/manual.html#expand-macro-recursively).
2728

28-
Note that when viewing expanded macro code, you're likely to encounter unusually verbose code. The
29-
reason is because generated code can sometimes clash with other code in an application. In order
30-
to prevent issues, `proc_macro` "hygiene" is adhered to. Some examples include:
29+
Output from the `html!` macro is often pretty terse! This is a feature: machine-generated code can
30+
sometimes clash with other code in an application. In order to prevent issues, `proc_macro`
31+
"hygiene" is adhered to. Some examples include:
3132

3233
1. Instead of using `yew::<module>` the macro generates `::yew::<module>` to make sure that the
3334
Yew package is referenced correctly. This is also why `::alloc::vec::Vec::new()` is called instead
3435
of just `Vec::new()`.
35-
2. Due to potential trait method name collisions, `<Type as Trait>` is used to make sure that we're using items from the right trait.
36+
2. Due to potential trait method name collisions, `<Type as Trait>` is used to make sure that we're
37+
using members from the correct trait.
3638

3739
## What is a virtual DOM?
3840

website/docs/advanced-topics/portals.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ title: "Portals"
33
description: "Rendering into out-of-tree DOM nodes"
44
---
55

6-
## How to think about portals?
6+
## What is a portal?
77

88
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.
99
`yew::create_portal(child, host)` returns a `Html` value that renders `child` not hierarchically under its parent component,
1010
but as a child of the `host` element.
1111

1212
## Usage
1313

14-
Typical uses of portals can include modal dialogs and hovercards, as well as more technical applications such as controlling the contents of an element's [`shadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot), appending stylesheets to the surrounding document's `<head>` and collecting referenced elements inside a central `<defs>` element of an `<svg>`.
14+
Typical uses of portals can include modal dialogs and hovercards, as well as more technical applications
15+
such as controlling the contents of an element's
16+
[`shadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot), appending
17+
stylesheets to the surrounding document's `<head>` and collecting referenced elements inside a
18+
central `<defs>` element of an `<svg>`.
1519

16-
Note that `yew::create_portal` is a rather low-level building block, on which other components should be built that provide the interface for your specific use case. As an example, here is a simple modal dialogue that renders its `children` into an element outside `yew`'s control, identified by the `id="modal_host"`.
20+
Note that `yew::create_portal` is a low-level building block. Libraries should use it to implement
21+
higher-level APIs which can then be consumed by applications. For example, here is a
22+
simple modal dialogue that renders its `children` into an element outside `yew`'s control,
23+
identified by the `id="modal_host"`.
1724

1825
```rust
1926
use yew::{html, create_portal, function_component, Children, Properties, Html};

website/docs/concepts/html/events.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ for the behaviour of `JsCast` but with the smaller scope of events and their tar
289289
similar to what you would using `JsCast`.
290290
:::
291291

292-
The `TargetCast` trait builds off of `JsCast` and is specialized towards getting typed event targets
293-
from events.
292+
The `TargetCast` trait is built on top of `JsCast` and is specialized towards getting typed event
293+
targets from events.
294294

295295
`TargetCast` comes with Yew so no need to add a dependency in order to use the trait methods on events
296296
but it works in a very similar way to `JsCast`.

website/docs/concepts/wasm-bindgen/introduction.mdx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ sidebar_label: wasm-bindgen
77
high-level interactions between Wasm modules and JavaScript; it is built with Rust by
88
[The Rust and WebAssembly Working Group](https://rustwasm.github.io/).
99

10-
Yew builds off `wasm-bindgen` and specifically uses the following of its crates:
10+
Yew uses `wasm-bindgen` to interact with the browser through a number of crates:
1111

1212
- [`js-sys`](https://crates.io/crates/js-sys)
1313
- [`wasm-bindgen`](https://crates.io/crates/wasm-bindgen)
1414
- [`wasm-bindgen-futures`](https://crates.io/crates/wasm-bindgen-futures)
1515
- [`web-sys`](https://crates.io/crates/web-sys)
1616

1717
This section will explore some of these crates in a high level in order to make it easier to understand
18-
and use `wasm-bindgen` APIs with Yew. For a more in-depth guide into `wasm-bindgen` and it's associated
18+
and use `wasm-bindgen` APIs with Yew. For a more in-depth guide to `wasm-bindgen` and its associated
1919
crates then check out [The `wasm-bindgen` Guide](https://rustwasm.github.io/docs/wasm-bindgen/).
2020

2121
For documentation on the above crates check out [`wasm-bindgen docs.rs`](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/index.html).
@@ -33,14 +33,13 @@ types / traits you will see pop up again and again.
3333

3434
### `#[wasm_bindgen]` macro
3535

36-
The `#[wasm_bindgen]` macro, in a high level view, is your translator between Rust and JavaScript, it
37-
allows you to describe imported JavaScript types in terms of Rust and vice versa. Using this macro
38-
is more advanced, and you shouldn't need to reach for it unless you are trying to interop with an
39-
external JavaScript library. The `js-sys` and `web-sys` crates are essentially imported types using
40-
this macro for JavaScript types and the browser API respectively.
36+
The `#[wasm_bindgen]` macro provides an interface between Rust and JavaScript, providing a system
37+
for translating between the two. Using this macro is more advanced, and you shouldn't need to reach
38+
for it unless you are trying to use an external JavaScript library. The `js-sys` and `web-sys`
39+
crates expose `wasm-bindgen` definitions for built-in Javascript types and browser APIs.
4140

4241
Let's go over a simple example of using the `#[wasm-bindgen]` macro to import some specific flavours
43-
of the [`console.log`](https://developer.mozilla.org/en-US/docs/Web/API/Console/log).
42+
of the [`console.log`](https://developer.mozilla.org/en-US/docs/Web/API/Console/log) function.
4443

4544
```rust ,no_run
4645
use wasm_bindgen::prelude::*;
@@ -78,14 +77,15 @@ _This example was adapted from [1.2 Using console.log of The `wasm-bindgen` Guid
7877

7978
### Simulating inheritance
8079

81-
Inheritance between JavaScript classes is a big part of the language and is a major part of how the
82-
Document Object Model (DOM). When types are imported using `wasm-bindgen` you can
83-
also add attributes that describe its inheritance.
80+
Inheritance between JavaScript classes is a core feature of the Javascript language, and the DOM
81+
(Document Object Model) is designed around it. When types are imported using `wasm-bindgen` you can
82+
also add attributes that describe their inheritance.
8483

85-
In Rust this inheritance is simulated using the [`Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html)
84+
In Rust this inheritance is represented using the [`Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html)
8685
and [`AsRef`](https://doc.rust-lang.org/std/convert/trait.AsRef.html) traits. An example of this
8786
might help; so say you have three types `A`, `B`, and `C` where `C` extends `B` which in turn
8887
extends `A`.
88+
8989
When importing these types the `#[wasm-bindgen]` macro will implement the `Deref` and `AsRef`
9090
traits in the following way:
9191

@@ -99,8 +99,7 @@ it was `&B` or `&A`.
9999

100100
Its important to note that every single type imported using `#[wasm-bindgen]` has the same root type,
101101
you can think of it as the `A` in the example above, this type is [`JsValue`](#jsvalue) which has
102-
its own section
103-
below.
102+
its own section below.
104103

105104
_[extends section in The `wasm-bindgen` Guide](https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-js-imports/extends.html)_
106105

@@ -109,19 +108,19 @@ _[extends section in The `wasm-bindgen` Guide](https://rustwasm.github.io/docs/w
109108
This is a representation of an object owned by JavaScript, this is a root catch-all type for `wasm-bindgen`.
110109
Any type that comes from `wasm-bindgen` is a `JsValue` and this is because JavaScript doesn't have
111110
a strong type system so any function that accepts a variable `x` doesn't define its type so `x` can be
112-
a valid JavaScript value; hence `JsValue`. So when you are working with imported functions or types that
111+
a valid JavaScript value; hence `JsValue`. If you are working with imported functions or types that
113112
accept a `JsValue`, then any imported value is _technically_ valid.
114113

115-
`JsValue` can be accepted by a function but that function may still only expect certain types and this
114+
`JsValue` can be accepted by a function but that function may still only accept certain types and this
116115
can lead to panics - so when using raw `wasm-bindgen` APIs check the documentation of the JavaScript
117-
being imported whether an exception will be caused if that value is not a certain type.
116+
being imported as to whether an exception (panic) will be raised if that value is not a certain type.
118117

119118
_[`JsValue` documentation](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/struct.JsValue.html)._
120119

121120
### [`JsCast`](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/trait.JsCast.html)
122121

123-
Rust has a strong type system and JavaScript...doesn't 😞 So in order for Rust to maintain these
124-
strong types but still be convenient the web assembly group came up with a pretty neat trait `JsCast`.
122+
Rust has a strong type system and JavaScript...doesn't 😞. In order for Rust to maintain these
123+
strong types but still be convenient the WebAssembly group came up with a pretty neat trait `JsCast`.
125124
Its job is to help you move from one JavaScript "type" to another, which sounds vague, but it means
126125
that if you have one type which you know is really another then you can use the functions of `JsCast`
127126
to jump from one type to the other. It's a nice trait to get to know when working with `web-sys`,
@@ -195,9 +194,10 @@ _[`js-sys` documentation](https://rustwasm.github.io/wasm-bindgen/api/js_sys/ind
195194
## [`wasm-bindgen-futures`](https://crates.io/crates/wasm-bindgen-futures)
196195

197196
The `wasm-bindgen-futures` crate provides a bridge for working with JavaScript Promise types as a
198-
Rust Future, and similarly contains utilities to turn a rust Future into a JavaScript Promise.
199-
This can be useful when working with asynchronous or otherwise blocking work in Rust (wasm),
200-
and provides the ability to interoperate with JavaScript events and JavaScript I/O primitives.
197+
Rust [`Future`](https://doc.rust-lang.org/stable/std/future/trait.Future.html), and contains
198+
utilities to turn a rust Future into a JavaScript Promise. This can be useful when working with
199+
asynchronous or otherwise blocking work in Rust (wasm), and provides the ability to interoperate
200+
with JavaScript events and JavaScript I/O primitives.
201201

202202
There are three main interfaces in this crate currently:
203203

website/docs/getting-started/build-a-sample-app.mdx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ cd yew-app
3131

3232
### Run a hello world example
3333

34-
To verify the Rust environment is setup, run the initial project using the cargo build tool. After output about the build process, you should see the expected "Hello World" message.
34+
To verify the Rust environment is setup, run the initial project using `cargo run`. You should see
35+
a "Hello World!" message.
3536

3637
```bash
3738
cargo run
39+
# output: Hello World!
3840
```
3941

40-
### Converting the project into a Yew web application
42+
### Setting up the project as a Yew web application
4143

4244
To convert this simple command line application to a basic Yew web application, a few changes are needed.
4345

@@ -58,12 +60,13 @@ yew = "0.19"
5860

5961
#### Update main.rs
6062

61-
We need to generate a template which sets up a root Component called `App` which renders a button that updates its value when clicked.
62-
Replace the contents of `src/main.rs` with the following code.
63+
We need to generate a template which sets up a root Component called `App` which renders a button
64+
that updates its value when clicked. Replace the contents of `src/main.rs` with the following code.
6365

6466
:::note
65-
The line `yew::start_app::<App>()` inside `main()` starts your application and mounts it to the page's `<body>` tag.
66-
If you would like to start your application with any dynamic properties, you can instead use `yew::start_app_with_props::<App>(..)`.
67+
The call to `yew::start_app::<App>()` inside the `main` function starts your application and mounts
68+
it to the page's `<body>` tag. If you would like to start your application with any dynamic
69+
properties, you can instead use `yew::start_app_with_props::<App>(..)`.
6770
:::
6871

6972
```rust ,no_run, title=main.rs
@@ -115,7 +118,7 @@ Run the following command to build and serve the application locally.
115118
trunk serve
116119
```
117120

118-
Trunk will helpfully rebuild your application if you modify any of its files.
121+
Trunk will rebuild your application if you modify any of its source code files.
119122

120123
## Congratulations
121124

website/docs/getting-started/examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Examples"
33
---
44

5-
The Yew repository is chock-full of [examples] (in various states of maintenance).
5+
The Yew repository is contains many [examples] (in various states of maintenance).
66
We recommend perusing them to get a feel for how to use different features of the framework.
77
We also welcome Pull Requests and issues for when they inevitably get neglected and need some ♥️
88

website/docs/getting-started/introduction.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Set yourself up for success"
55
---
66

77

8-
Your local development environment will need a couple of tools to compile, build, package and debug your Yew application.
8+
You will need a couple of tools to compile, build, package and debug your Yew application.
99
When getting started, we recommend using [Trunk](https://trunkrs.dev/). Trunk is a WASM web application
1010
bundler for Rust.
1111

@@ -14,24 +14,26 @@ bundler for Rust.
1414
To install Rust, follow the [official instructions](https://www.rust-lang.org/tools/install).
1515

1616
:::important
17-
The minimum supported Rust version (MSRV) for Yew is `1.49.0`. Older versions can cause unexpected issues accompanied
18-
by incomprehensible error messages. You can check your toolchain version using `rustup show` (under "active toolchain")
19-
or alternatively `rustc --version`. To update your toolchain, run `rustup update`.
17+
The minimum supported Rust version (MSRV) for Yew is `1.56.0`. Older versions can cause unexpected
18+
issues accompanied by incomprehensible error messages. You can check your toolchain version using
19+
`rustup show` (under "active toolchain") or alternatively `rustc --version`. To update your
20+
toolchain, run `rustup update`.
2021
:::
2122

2223
## Install WebAssembly target
2324

24-
Rust can compile source codes for different "targets" (e.g. different processors). The compilation target for
25-
browser-based WebAssembly is called `wasm32-unknown-unknown`.
26-
The following command will add this target to your development environment.
25+
Rust can compile source codes for different "targets" (e.g. different processors). The compilation
26+
target for browser-based WebAssembly is called `wasm32-unknown-unknown`. The following command will
27+
add the WebAssembly target to your development environment.
2728

2829
```shell
2930
rustup target add wasm32-unknown-unknown
3031
```
3132

3233
## Install Trunk
3334

34-
Trunk is the recommended tool for managing deployment and packaging, and will be used throughout the documentation and examples.
35+
Trunk is the recommended tool for managing deployment and packaging, and is used throughout the
36+
documentation and examples.
3537

3638
```shell
3739
# note that this might take a while to install, because it compiles everything from scratch

website/docs/migration-guides/yew-agent/from-0_1_0-to-0_2_0.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ title: "From 0.1.0 to 0.2.0"
66

77
The `Context` and `Job` Agents have been removed in favour of Yew's Context API.
88

9-
You can see the updated [`pub_sub`](https://github.com/yewstack/yew/tree/master/examples/pub_sub) example about how to use Context API.
9+
You can see the updated [`pub_sub`](https://github.com/yewstack/yew/tree/master/examples/pub_sub)
10+
which demonstrate how to use the context API.
1011

1112
For users of `yew_agent::utils::store`, you may switch to third party solutions like: [Yewdux](https://github.com/intendednull/yewdux) or [Bounce](https://github.com/futursolo/bounce).
1213

13-
## `Threaded` is separated into `PublicAgent` and `PrivateAgent`
14+
## `Threaded` has been separated into `PublicAgent` and `PrivateAgent`
1415

1516
Replace `use yew_agent::Threaded;` with `use yew_agent::PublicAgent;`.
1617

website/docs/migration-guides/yew-router/from-0_15_0-to-0_16_0.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: "From 0.15.0 to 0.16.0"
33
---
44

5-
The router API has been completely redone in `0.16.0`.
5+
The router API has been completely rewritten in `0.16.0`.
66

7-
There would be to many things to list out here, so we highly recommend to read up on the [router documentation](./../../concepts/router) and adapt your app accordingly.
7+
Because it is such a radical change, there are too many things to list out here, so we highly
8+
recommend to read the updated [router documentation](./../../concepts/router) and adapt your app
9+
accordingly.

website/docs/migration-guides/yew/from-0_18_0-to-0_19_0.mdx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import TabItem from '@theme/TabItem';
77

88
`Yew 0.19.0` has changed a lot, thus this migration will not cover ALL of the changes.
99

10-
Instead only the most impacting changes are mentioned and the rest should be picked up by cargo.
10+
Instead only the most impactful changes are mentioned and the rest should be picked up by `cargo`.
1111

12-
## html! requirement for braces around most props
12+
## `html!` requirement for braces around most props
1313

14-
Put it simply almost all the time you have to provide braces for props:
14+
The syntax of the `html!` macro has been updated, such that in most cases you will need to enclose
15+
props with braces.
1516

1617
<Tabs>
1718
<TabItem value="Invalid" label="Invalid">
@@ -40,7 +41,7 @@ html!{
4041
</TabItem>
4142
<TabItem value="Shorthand" label="Shorthand">
4243

43-
Also now you can use a shorthand if prop and variable names are the same:
44+
Shorthand initialization has been added:
4445

4546
```rust {4}, ignore
4647
let age = 1;
@@ -54,19 +55,21 @@ html!{
5455
</TabItem>
5556
</Tabs>
5657

57-
There is a community provided regex to help with this change, though we cant promise it will work all the time.
58+
There is a community provided regex to help automate the update, though we can't promise it will work
59+
all the time.
5860

59-
It for sure breaks when it encounters closures, specifically `|_|` syntax.
61+
It breaks when it encounters closures (specifically the `|_|` syntax).
6062

6163
find with `=(?![{">=\s])([^\s></]*(\s!{0,1}[=|&]{2}\s[^\s></]*)*)`
6264

6365
replace with `={$1}`
6466

6567
## Function components
6668

67-
[Function components](./../../concepts/function-components/introduction) are a brand new way to write components that require less boilerplate than their structural counter part.
69+
[Function components](./../../concepts/function-components/introduction) are a brand new way to write components that
70+
requires less boilerplate than their structural counterpart.
6871

69-
While this change does not force you to change your codebase, this migration time is a good opportunity to start using them in your codebase.
72+
While this change does not force you to change your codebase, as you migrate from `0.18` to `0.19`, this migration time might present a good opportunity to start using them in your codebase.
7073

7174
## Struct components lifecycle methods and ctx
7275

@@ -128,8 +131,9 @@ html! {
128131

129132
## New crate - yew-agent
130133

131-
Yew agents were removed to their separate crate, see [yew agents migration guide](./../yew-agent/from-0_0_0-to-0_1_0)
134+
Yew agents were removed to a separate crate, see [yew agents migration guide](./../yew-agent/from-0_0_0-to-0_1_0)
132135

133136
## Ending note
134137

135-
We are sorry if some things are not covered in this guide as it was truly a huge update and we hope that the uncovered issues will be clearly explained by cargo check/build/clippy.
138+
We are sorry if some things are not covered in this guide as it was truly a huge update and we hope
139+
that the uncovered issues will be clearly explained in error messages emitted by the Rust compiler.

0 commit comments

Comments
 (0)