Skip to content

Commit 507e887

Browse files
author
Rich Harris
committed
tidy up
1 parent 84121f7 commit 507e887

File tree

4 files changed

+26
-39
lines changed

4 files changed

+26
-39
lines changed

content/tutorial/03-advanced-svelte/09-special-elements/09-svelte-options/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ We'll use the `immutable` option as an example. In this app, the `<Todo>` compon
88

99
We can optimise this by telling the `<Todo>` component to expect _immutable_ data. This means that we're promising never to _mutate_ the `todo` prop, but will instead create new todo objects whenever things change.
1010

11-
Add this to the top of the `Todo.svelte` file:
11+
Add this to the top of `Todo.svelte`:
1212

1313
```svelte
1414
/// file: Todo.svelte
15-
<svelte:options immutable={true}/>
15+
<svelte:options immutable={true} />
1616
```
1717

1818
> You can shorten this to `<svelte:options immutable/>` if you prefer.

content/tutorial/03-advanced-svelte/09-special-elements/09-svelte-options/app-a/src/lib/App.svelte

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
44
let todos = [
55
{ id: 1, done: true, text: 'wash the car' },
6-
{
7-
id: 2,
8-
done: false,
9-
text: 'take the dog for a walk'
10-
},
6+
{ id: 2, done: false, text: 'take the dog for a walk' },
117
{ id: 3, done: false, text: 'mow the lawn' }
128
];
139
@@ -29,6 +25,15 @@
2925
</script>
3026

3127
<h2>Todos</h2>
32-
{#each todos as todo}
33-
<Todo {todo} on:click={() => toggle(todo)} />
34-
{/each}
28+
<ul>
29+
{#each todos as todo}
30+
<li><Todo {todo} on:change={() => toggle(todo)} /></li>
31+
{/each}
32+
</ul>
33+
34+
<style>
35+
ul {
36+
list-style: none;
37+
padding-left: 0.5em;
38+
}
39+
</style>

content/tutorial/03-advanced-svelte/09-special-elements/09-svelte-options/app-a/src/lib/Todo.svelte

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,16 @@
44
55
export let todo;
66
7-
let button;
7+
let label;
88
99
afterUpdate(() => {
10-
flash(button);
10+
flash(label);
1111
});
1212
</script>
1313

1414
<!-- the text will flash red whenever
1515
the `todo` object changes -->
16-
<button bind:this={button} type="button" on:click>
17-
{todo.done ? '👍' : ''}
16+
<label bind:this={label}>
17+
<input type="checkbox" checked={todo.done} on:change />
1818
{todo.text}
19-
</button>
20-
21-
<style>
22-
button {
23-
all: unset;
24-
display: block;
25-
cursor: pointer;
26-
line-height: 1.5;
27-
}
28-
</style>
19+
</label>
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
<svelte:options immutable={true} />
1+
<svelte:options immutable />
22

33
<script>
44
import { afterUpdate } from 'svelte';
55
import flash from './flash.js';
66
77
export let todo;
88
9-
let button;
9+
let label;
1010
1111
afterUpdate(() => {
12-
flash(button);
12+
flash(label);
1313
});
1414
</script>
1515

1616
<!-- the text will flash red whenever
1717
the `todo` object changes -->
18-
<button bind:this={button} type="button" on:click>
19-
{todo.done ? '👍' : ''}
18+
<label bind:this={label}>
19+
<input type="checkbox" checked={todo.done} on:change />
2020
{todo.text}
21-
</button>
22-
23-
<style>
24-
button {
25-
all: unset;
26-
display: block;
27-
cursor: pointer;
28-
line-height: 1.5;
29-
}
30-
</style>
21+
</label>

0 commit comments

Comments
 (0)