Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions docs/tutorial/components-and-reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,36 @@ Because this is such a common pattern, Marko provides a [shorthand](../reference
<div>It's ${degF}°F</div>
```

## Adding Computed Values
<input type="number" value=degF valueChange(value) { degF = value }>
<div>It's ${degF}°F</div>
```

Now we can use [the `<const>` tag](../reference/core-tag.md#const) to convert to celsius!

```marko
<let/degF=80>

<input type="number" value:=degF>
<div>It's ${degF}°F</div>
```

## Adding Computed Values

The `input` tag contains a _string_, so let's convert it to a number using [the `<const>` tag](../reference/core-tag.md#const).

```marko
<let/degFString="80">
<const/degF=parseFloat(degFString)>

<input type="number" value:=degFString>
<div>It's ${degF}°F</div>
```

Now we can use another `<const>` to convert to celsius!

```marko
<let/degFString="80">
<const/degF=(+degFString)>
<const/degC=(degF - 32) * 5 / 9>

<input type="number" value:parseFloat:=degF>
Expand All @@ -78,7 +102,8 @@ Since `degC` is a [tag variable](../reference/language.md#tag-variables), its ch
Now that we have a reactive variable, let's see what else we can do! Maybe some notes about the temperature, using [conditional tags](../reference/core-tag.md#if--else)?

```marko
<let/degF=80>
<let/degFString="80">
<const/degF=(+degFString)>
<const/degC=(degF - 32) * 5 / 9>

<input type="number" value:parseFloat:=degF>
Expand All @@ -102,7 +127,8 @@ Now that we have a reactive variable, let's see what else we can do! Maybe some
Or what about a temperature gauge, with some fancy CSS?

```marko
<let/degF=80>
<let/degFString="80">
<const/degF=(+degFString)>
<const/degC=(degF - 32) * 5 / 9>

<input type="number" value:parseFloat:=degF>
Expand Down Expand Up @@ -143,7 +169,8 @@ Actually, this is getting a little bit too complex to all put in one place. Mayb

```marko
/* index.marko */
<let/degF=80>
<let/degFString="80">
<const/degF=(+degFString)>
<const/degC=(degF - 32) * 5 / 9>

<input type="number" value:parseFloat:=degF>
Expand Down