-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: bring over examples #294
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3cd845d
bring over examples (old syntax) and wire them up correctly
dummdidumm b95190c
expose examples in the UI through select
dummdidumm fdc825a
migrate to runes, remove deprecated stuff
dummdidumm a801f60
add redirect
dummdidumm b2bccc8
prettier
dummdidumm f293a97
fix entries generation
dummdidumm 183ee89
use temporary redirects so we don't regret it in the future when we w…
dummdidumm f647563
get it working on build by moving examples retrieval into prerendered…
dummdidumm 8a6e5f5
lint
dummdidumm 115835c
move examples dropdown to icon on the right
dummdidumm b036962
show "edited" in the title once changing contents
dummdidumm ceee901
add "create new" option
dummdidumm 04d7179
add examples to search (with low priority)
dummdidumm 2936015
merge main, minor style tweaks
Rich-Harris 2996202
fix
Rich-Harris 50a95c9
remove duplicate content
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
apps/svelte.dev/content/examples/00-introduction/00-hello-world/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let name = 'world'; | ||
</script> | ||
|
||
<h1>Hello {name}!</h1> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/00-introduction/00-hello-world/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Hello world' | ||
--- |
7 changes: 7 additions & 0 deletions
7
apps/svelte.dev/content/examples/00-introduction/01-dynamic-attributes/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let src = '/tutorial/image.gif'; | ||
let name = 'Rick Astley'; | ||
</script> | ||
|
||
<!-- {src} is short for src={src} --> | ||
<img {src} alt="{name} dancing" /> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/00-introduction/01-dynamic-attributes/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Dynamic attributes' | ||
--- |
9 changes: 9 additions & 0 deletions
9
apps/svelte.dev/content/examples/00-introduction/02-styling/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<p>Styled!</p> | ||
|
||
<style> | ||
p { | ||
color: purple; | ||
font-family: 'Comic Sans MS', cursive; | ||
font-size: 2em; | ||
} | ||
</style> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/00-introduction/02-styling/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Styling' | ||
--- |
14 changes: 14 additions & 0 deletions
14
apps/svelte.dev/content/examples/00-introduction/03-nested-components/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
</script> | ||
|
||
<p>These styles...</p> | ||
<Nested /> | ||
|
||
<style> | ||
p { | ||
color: purple; | ||
font-family: 'Comic Sans MS', cursive; | ||
font-size: 2em; | ||
} | ||
</style> |
1 change: 1 addition & 0 deletions
1
apps/svelte.dev/content/examples/00-introduction/03-nested-components/+assets/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>...don't affect this element</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/00-introduction/03-nested-components/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Nested components' | ||
--- |
5 changes: 5 additions & 0 deletions
5
apps/svelte.dev/content/examples/00-introduction/04-html-tags/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let string = `here's some <strong>HTML!!!</strong>`; | ||
</script> | ||
|
||
<p>{@html string}</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/00-introduction/04-html-tags/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'HTML tags' | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Introduction' | ||
--- |
12 changes: 12 additions & 0 deletions
12
apps/svelte.dev/content/examples/01-reactivity/00-reactive-assignments/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
let count = $state(0); | ||
|
||
function handleClick() { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<button onclick={handleClick}> | ||
Clicked {count} | ||
{count === 1 ? 'time' : 'times'} | ||
</button> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/01-reactivity/00-reactive-assignments/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Reactive assignments' | ||
--- |
17 changes: 17 additions & 0 deletions
17
apps/svelte.dev/content/examples/01-reactivity/01-reactive-declarations/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
let count = $state(1); | ||
|
||
let doubled = $derived(count * 2); | ||
let quadrupled = $derived(doubled * 2); | ||
|
||
function handleClick() { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<button onclick={handleClick}> | ||
Count: {count} | ||
</button> | ||
|
||
<p>{count} * 2 = {doubled}</p> | ||
<p>{doubled} * 2 = {quadrupled}</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/01-reactivity/01-reactive-declarations/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Reactive declarations' | ||
--- |
19 changes: 19 additions & 0 deletions
19
apps/svelte.dev/content/examples/01-reactivity/02-reactive-statements/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
let count = $state(0); | ||
|
||
$effect(() => { | ||
if (count >= 10) { | ||
alert(`count is dangerously high!`); | ||
count = 9; | ||
} | ||
}); | ||
|
||
function handleClick() { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<button onclick={handleClick}> | ||
Clicked {count} | ||
{count === 1 ? 'time' : 'times'} | ||
</button> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/01-reactivity/02-reactive-statements/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Reactive statements' | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Reactivity' | ||
--- |
5 changes: 5 additions & 0 deletions
5
apps/svelte.dev/content/examples/02-props/00-declaring-props/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
</script> | ||
|
||
<Nested answer={42} /> |
5 changes: 5 additions & 0 deletions
5
apps/svelte.dev/content/examples/02-props/00-declaring-props/+assets/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let { answer } = $props(); | ||
</script> | ||
|
||
<p>The answer is {answer}</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/02-props/00-declaring-props/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Declaring props' | ||
--- |
6 changes: 6 additions & 0 deletions
6
apps/svelte.dev/content/examples/02-props/01-default-values/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
</script> | ||
|
||
<Nested answer={42} /> | ||
<Nested /> |
5 changes: 5 additions & 0 deletions
5
apps/svelte.dev/content/examples/02-props/01-default-values/+assets/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let { answer = 'a mystery' } = $props(); | ||
</script> | ||
|
||
<p>The answer is {answer}</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/02-props/01-default-values/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Default values' | ||
--- |
12 changes: 12 additions & 0 deletions
12
apps/svelte.dev/content/examples/02-props/02-spread-props/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
import Info from './Info.svelte'; | ||
|
||
const pkg = { | ||
name: 'svelte', | ||
version: 3, | ||
speed: 'blazing', | ||
website: 'https://svelte.dev' | ||
}; | ||
</script> | ||
|
||
<Info {...pkg} /> |
14 changes: 14 additions & 0 deletions
14
apps/svelte.dev/content/examples/02-props/02-spread-props/+assets/Info.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script> | ||
let { | ||
name, | ||
version, | ||
speed, | ||
website | ||
} = $props(); | ||
</script> | ||
|
||
<p> | ||
The <code>{name}</code> package is {speed} fast. Download version {version} from | ||
<a href="https://www.npmjs.com/package/{name}">npm</a> | ||
and <a href={website}>learn more here</a> | ||
</p> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/02-props/02-spread-props/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Spread props' | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Props' | ||
--- |
15 changes: 15 additions & 0 deletions
15
apps/svelte.dev/content/examples/03-logic/00-if-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
let user = $state({ loggedIn: false }); | ||
|
||
function toggle() { | ||
user.loggedIn = !user.loggedIn; | ||
} | ||
</script> | ||
|
||
{#if user.loggedIn} | ||
<button onclick={toggle}> Log out </button> | ||
{/if} | ||
|
||
{#if !user.loggedIn} | ||
<button onclick={toggle}> Log in </button> | ||
{/if} |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/00-if-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'If blocks' | ||
--- |
13 changes: 13 additions & 0 deletions
13
apps/svelte.dev/content/examples/03-logic/01-else-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
let user = $state({ loggedIn: false }); | ||
|
||
function toggle() { | ||
user.loggedIn = !user.loggedIn; | ||
} | ||
</script> | ||
|
||
{#if user.loggedIn} | ||
<button onclick={toggle}> Log out </button> | ||
{:else} | ||
<button onclick={toggle}> Log in </button> | ||
{/if} |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/01-else-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Else blocks' | ||
--- |
11 changes: 11 additions & 0 deletions
11
apps/svelte.dev/content/examples/03-logic/02-else-if-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let x = 7; | ||
</script> | ||
|
||
{#if x > 10} | ||
<p>{x} is greater than 10</p> | ||
{:else if 5 > x} | ||
<p>{x} is less than 5</p> | ||
{:else} | ||
<p>{x} is between 5 and 10</p> | ||
{/if} |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/02-else-if-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Else-if blocks' | ||
--- |
19 changes: 19 additions & 0 deletions
19
apps/svelte.dev/content/examples/03-logic/03-each-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
let cats = [ | ||
{ id: 'J---aiyznGQ', name: 'Keyboard Cat' }, | ||
{ id: 'z_AbfPXTKms', name: 'Maru' }, | ||
{ id: 'OUtn3pvWmpg', name: 'Henri The Existential Cat' } | ||
]; | ||
</script> | ||
|
||
<h1>The Famous Cats of YouTube</h1> | ||
|
||
<ul> | ||
{#each cats as { id, name }, i} | ||
<li> | ||
<a target="_blank" rel="noreferrer" href="https://www.youtube.com/watch?v={id}"> | ||
{i + 1}: {name} | ||
</a> | ||
</li> | ||
{/each} | ||
</ul> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/03-each-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Each blocks' | ||
--- |
33 changes: 33 additions & 0 deletions
33
apps/svelte.dev/content/examples/03-logic/04-keyed-each-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script> | ||
import Thing from './Thing.svelte'; | ||
|
||
let things = $state([ | ||
{ id: 1, color: 'darkblue' }, | ||
{ id: 2, color: 'indigo' }, | ||
{ id: 3, color: 'deeppink' }, | ||
{ id: 4, color: 'salmon' }, | ||
{ id: 5, color: 'gold' } | ||
]); | ||
|
||
function handleClick() { | ||
things = things.slice(1); | ||
} | ||
</script> | ||
|
||
<button onclick={handleClick}> Remove first thing </button> | ||
|
||
<div style="display: grid; grid-template-columns: 1fr 1fr; grid-gap: 1em"> | ||
<div> | ||
<h2>Keyed</h2> | ||
{#each things as thing (thing.id)} | ||
<Thing current={thing.color} /> | ||
{/each} | ||
</div> | ||
|
||
<div> | ||
<h2>Unkeyed</h2> | ||
{#each things as thing} | ||
<Thing current={thing.color} /> | ||
{/each} | ||
</div> | ||
</div> |
24 changes: 24 additions & 0 deletions
24
apps/svelte.dev/content/examples/03-logic/04-keyed-each-blocks/+assets/Thing.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
// `current` is updated whenever the prop value changes... | ||
let { current } = $props(); | ||
|
||
// ...but `initial` is fixed upon initialisation | ||
const initial = current; | ||
</script> | ||
|
||
<p> | ||
<span style="background-color: {initial}">initial</span> | ||
<span style="background-color: {current}">current</span> | ||
</p> | ||
|
||
<style> | ||
span { | ||
display: inline-block; | ||
padding: 0.2em 0.5em; | ||
margin: 0 0.2em 0.2em 0; | ||
width: 4em; | ||
text-align: center; | ||
border-radius: 0.2em; | ||
color: white; | ||
} | ||
</style> |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/04-keyed-each-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Keyed each blocks' | ||
--- |
28 changes: 28 additions & 0 deletions
28
apps/svelte.dev/content/examples/03-logic/05-await-blocks/+assets/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script> | ||
let promise = $state(getRandomNumber()); | ||
|
||
async function getRandomNumber() { | ||
const res = await fetch(`/tutorial/random-number`); | ||
const text = await res.text(); | ||
|
||
if (res.ok) { | ||
return text; | ||
} else { | ||
throw new Error(text); | ||
} | ||
} | ||
|
||
function handleClick() { | ||
promise = getRandomNumber(); | ||
} | ||
</script> | ||
|
||
<button onclick={handleClick}> generate random number </button> | ||
|
||
{#await promise} | ||
<p>...waiting</p> | ||
{:then number} | ||
<p>The number is {number}</p> | ||
{:catch error} | ||
<p style="color: red">{error.message}</p> | ||
{/await} |
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/examples/03-logic/05-await-blocks/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Await blocks' | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: 'Logic' | ||
--- |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't work — cross-origin isolation gremlins strike again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and this time it's impossible to get it working because we can't add the
relaxed
attribute on the iframe for security reasons.I really think we need to make navigations to the SvelteKit tutorial full page reloads, and navigations away from it, too, and only set the headers on the SvelteKit tutorial. That would solve all this iframe/img/audio/video bullshit we had to deal with the last days. I don't expect people to quickly jump back and forth between that tutorial and something else, so it will be fine in practise.