Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit507e887

Browse files
author
Rich Harris
committed
tidy up
1 parent84121f7 commit507e887

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 ofthe`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-
{#eachtodosastodo}
33-
<Todo {todo}on:click={()=>toggle(todo)} />
34-
{/each}
28+
<ul>
29+
{#eachtodosastodo}
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
exportlet todo;
66
7-
letbutton;
7+
letlabel;
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-
<buttonbind:this={button}type="button"on:click>
17-
{todo.done?'👍':''}
16+
<labelbind:this={label}>
17+
<inputtype="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:optionsimmutable={true} />
1+
<svelte:optionsimmutable />
22

33
<script>
44
import {afterUpdate }from'svelte';
55
importflashfrom'./flash.js';
66
77
exportlet todo;
88
9-
letbutton;
9+
letlabel;
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-
<buttonbind:this={button}type="button"on:click>
19-
{todo.done?'👍':''}
18+
<labelbind:this={label}>
19+
<inputtype="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)

[8]ページ先頭

©2009-2025 Movatter.jp