Skip to content

Commit 037ac2f

Browse files
authored
docs: update transitions tutorial (sveltejs#8822)
fixes sveltejs#8820
1 parent 79e7ccc commit 037ac2f

File tree

8 files changed

+32
-24
lines changed

8 files changed

+32
-24
lines changed

documentation/tutorial/10-transitions/07-local-transitions/app-b/App.svelte renamed to documentation/tutorial/10-transitions/07-global-transitions/app-b/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
{#if showItems}
1919
{#each items.slice(0, i) as item}
20-
<div transition:slide|local>
20+
<div transition:slide|global>
2121
{item}
2222
</div>
2323
{/each}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Global transitions
3+
---
4+
5+
Ordinarily, transitions will only play on elements when their direct containing block is added or destroyed. In the example here, toggling the visibility of the entire list does not apply transitions to individual list elements.
6+
7+
Instead, we'd like transitions to not only play when individual items are added and removed with the slider but also when we toggle the checkbox.
8+
9+
We can achieve this with a _global_ transition, which plays when _any_ block containing the transitions is added or removed:
10+
11+
```svelte
12+
<div transition:slide|global>
13+
{item}
14+
</div>
15+
```
16+
17+
> In Svelte 3, transitions were global by default and you had to use the `|local` modifier to make them local.

documentation/tutorial/10-transitions/07-local-transitions/text.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/playground/start.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { readFileSync, writeFileSync } from 'node:fs';
22
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
34
import { watch } from 'rollup';
45
import serve from 'rollup-plugin-serve';
56
import * as svelte from '../svelte/src/compiler/index.js';
67

7-
let __dirname = new URL('.', import.meta.url).pathname;
8-
if (process.platform === 'win32') {
9-
__dirname = __dirname.slice(1); // else path.resolve fucks up
10-
}
8+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
119

1210
/** @returns {import('rollup').Plugin}*/
1311
function create_plugin(ssr = false) {

sites/svelte.dev/scripts/generate_examples.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { fileURLToPath } from 'node:url';
12
import { get_examples_data } from '../src/lib/server/examples/index.js';
23
import fs from 'node:fs';
34

45
const examples_data = get_examples_data(
5-
new URL('../../../documentation/examples', import.meta.url).pathname
6+
fileURLToPath(new URL('../../../documentation/examples', import.meta.url))
67
);
78

89
try {

sites/svelte.dev/src/routes/docs/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
}
211211
212212
onMount(() => {
213-
console.log(get_old_new_ids_map());
213+
console.log(get_old_new_ids_map()); // for debugging purposes in prod
214214
goto(get_url_to_redirect_to(), { replaceState: true });
215215
});
216216
</script>

sites/svelte.dev/src/routes/tutorial/[slug]/+page.server.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import {
33
get_tutorial_data,
44
get_tutorial_list
55
} from '$lib/server/tutorial/index.js';
6-
import { error } from '@sveltejs/kit';
6+
import { error, redirect } from '@sveltejs/kit';
77

88
export const prerender = true;
99

1010
export async function load({ params }) {
11+
if (params.slug === 'local-transitions') throw redirect(307, '/tutorial/global-transitions');
12+
1113
const tutorial_data = get_tutorial_data();
1214
const tutorials_list = get_tutorial_list(tutorial_data);
1315

@@ -24,7 +26,12 @@ export async function load({ params }) {
2426

2527
export async function entries() {
2628
const tutorials_list = get_tutorial_list(get_tutorial_data());
27-
return tutorials_list
29+
const slugs = tutorials_list
2830
.map(({ tutorials }) => tutorials)
2931
.flatMap((val) => val.map(({ slug }) => ({ slug })));
32+
33+
// to force redirect
34+
slugs.push({ slug: 'local-transitions' });
35+
36+
return slugs;
3037
}

0 commit comments

Comments
 (0)