Skip to content

Commit 87ba390

Browse files
Rich-HarrisRich Harris
and
Rich Harris
authored
tweaks (sveltejs#292)
Co-authored-by: Rich Harris <git@rich-harris.dev>
1 parent c279292 commit 87ba390

File tree

9 files changed

+27
-13
lines changed

9 files changed

+27
-13
lines changed

content/tutorial/01-svelte/01-introduction/03-dynamic-attributes/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Our image is missing a `src` — let's add one:
1111
<img +++src={src}+++ />
1212
```
1313

14-
That's better. But Svelte is giving us a warning:
14+
That's better. But if you hover over the `<img>` in the editor, Svelte is giving us a warning:
1515

1616
> A11y: &lt;img&gt; element should have an alt attribute
1717

content/tutorial/01-svelte/01-introduction/05-nested-components/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Nested components
44

55
It would be impractical to put your entire app in a single component. Instead, we can import components from other files and include them in our markup.
66

7-
Add a `<script>` tag that imports `Nested.svelte`...
7+
Add a `<script>` tag to the top of `App.svelte` that imports `Nested.svelte`...
88

99
```svelte
1010
/// file: App.svelte

content/tutorial/01-svelte/02-reactivity/01-reactive-assignments/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ To demonstrate it, we first need to wire up an event handler (we'll learn more a
99
```svelte
1010
/// file: App.svelte
1111
<button +++on:click={increment}+++>
12+
Clicked {count}
13+
{count === 1 ? 'time' : 'times'}
14+
</button>
1215
```
1316

1417
Inside the `increment` function, all we need to do is change the value of `count`:

content/tutorial/01-svelte/02-reactivity/03-reactive-statements/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can easily group statements together with a block:
1717
/// file: App.svelte
1818
$: +++{+++
1919
console.log(`the count is ${count}`);
20-
alert(`I SAID THE COUNT IS ${count}`);
20+
console.log(`this will also be logged whenever count changes`);
2121
+++}+++
2222
```
2323

content/tutorial/01-svelte/02-reactivity/04-updating-arrays-and-objects/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Updating arrays and objects
33
---
44

5-
Because Svelte's reactivity is triggered by assignments, using array methods like `push` and `splice` won't automatically cause updates. For example, clicking the 'Add a number' button doesn't currently do anything.
5+
Because Svelte's reactivity is triggered by assignments, using array methods like `push` and `splice` won't automatically cause updates. For example, clicking the 'Add a number' button doesn't currently do anything, even though we're calling `numbers.push(...)` inside `addNumber`.
66

77
One way to fix that is to add an assignment that would otherwise be redundant:
88

content/tutorial/01-svelte/03-props/03-spread-props/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
title: Spread props
33
---
44

5-
If you have an object of properties, you can 'spread' them onto a component instead of specifying each one:
5+
In this exercise, we've forgotten to specify the `version` prop expected by `PackageInfo.svelte`, meaning it shows 'version undefined'.
6+
7+
We _could_ fix it by adding the `version` prop...
8+
9+
```svelte
10+
/// file: App.svelte
11+
<PackageInfo
12+
name={pkg.name}
13+
speed={pkg.speed}
14+
+++version={pkg.version}+++
15+
website={pkg.website}
16+
/>
17+
```
18+
19+
...but since the properties of `pkg` correspond to the component's expected props, we can 'spread' them onto the component instead:
620

721
```svelte
822
/// file: App.svelte
9-
<PackageInfo +++{...pkg}+++/>
23+
<PackageInfo +++{...pkg}+++ />
1024
```
1125

1226
> Conversely, if you need to reference all the props that were passed into a component, including ones that weren't declared with `export`, you can do so by accessing `$$props` directly. It's not generally recommended, as it's difficult for Svelte to optimise, but it's useful in rare cases.

content/tutorial/01-svelte/03-props/03-spread-props/app-a/src/lib/App.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
44
const pkg = {
55
name: 'svelte',
6+
speed: 'blazing',
67
version: 3,
7-
speed: 'blazingly',
88
website: 'https://svelte.dev'
99
};
1010
</script>
1111

1212
<PackageInfo
1313
name={pkg.name}
14-
version={pkg.version}
1514
speed={pkg.speed}
1615
website={pkg.website}
1716
/>

content/tutorial/01-svelte/03-props/03-spread-props/app-a/src/lib/PackageInfo.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
</script>
99

1010
<p>
11-
The <code>{name}</code> package is {speed} fast. Download version {version}
12-
from
13-
<a {href}>npm</a>
14-
and <a href={website}>learn more here</a>
11+
The <code>{name}</code> package is {speed} fast. Download version {version} from
12+
<a {href}>npm</a> and <a href={website}>learn more here</a>
1513
</p>

content/tutorial/01-svelte/03-props/03-spread-props/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
const pkg = {
55
name: 'svelte',
6+
speed: 'blazing',
67
version: 3,
7-
speed: 'blazingly',
88
website: 'https://svelte.dev'
99
};
1010
</script>

0 commit comments

Comments
 (0)