Skip to content

Commit e7f5467

Browse files
authored
Merge pull request sveltejs#2432 from sveltejs/sveltejsgh-2194
Update a few examples
2 parents 7ad6349 + bb10298 commit e7f5467

File tree

21 files changed

+673
-712
lines changed

21 files changed

+673
-712
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { name, greeting } from './stores.js';
3+
</script>
4+
5+
<h1>{$greeting}</h1>
6+
<input value={$name}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { writable, derived } from 'svelte/store';
2+
3+
export const name = writable('world');
4+
5+
export const greeting = derived(
6+
name,
7+
$name => `Hello ${$name}!`
8+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
import { name, greeting } from './stores.js';
3+
</script>
4+
5+
<h1>{$greeting}</h1>
6+
<input bind:value={$name}>
7+
8+
<button on:click="{() => $name += '!'}">
9+
Add exclamation mark!
10+
</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { writable, derived } from 'svelte/store';
2+
3+
export const name = writable('world');
4+
5+
export const greeting = derived(
6+
name,
7+
$name => `Hello ${$name}!`
8+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Store bindings
3+
---
4+
5+
If a store is writable — i.e. it has a `set` method — you can bind to its value, just as you can bind to local component state.
6+
7+
In this example we have a writable store `name` and a derived store `greeting`. Update the `<input>` element:
8+
9+
```html
10+
<input bind:value={$name}>
11+
```
12+
13+
Changing the input value will now update `name` and all its dependents.
14+
15+
We can also assign directly to store values inside a component. Add a `<button>` element:
16+
17+
```html
18+
<button on:click="{() => $name += '!'}">
19+
Add exclamation mark!
20+
</button>
21+
```
22+
23+
The `$name += '!'` assignment is equivalent to `name.set($name + '!')`.

site/content/tutorial/10-transitions/07-deferred-transitions/app-a/App.svelte

-146
This file was deleted.

site/content/tutorial/10-transitions/07-deferred-transitions/app-a/crossfade.js

-65
This file was deleted.

0 commit comments

Comments
 (0)