Skip to content

Commit 3c3af89

Browse files
authored
add something to do on updated-store tutorial (sveltejs#544)
Co-authored-by: Rich Harris <[email protected]>
1 parent 7eac90f commit 3c3af89

File tree

3 files changed

+98
-30
lines changed

3 files changed

+98
-30
lines changed

content/tutorial/03-sveltekit/08-stores/03-updated-store/README.md

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,29 @@ title: updated
44

55
The `updated` store contains `true` or `false` depending on whether a new version of the app has been deployed since the page was first opened. For this to work, your `svelte.config.js` must specify `kit.version.pollInterval`.
66

7-
Version changes only happen in production, not during development. For that reason, `$updated` will always be `false` in this tutorial.
8-
9-
You can manually check for new versions, regardless of `pollInterval`, by calling `updated.check()`.
10-
117
```svelte
128
/// file: src/routes/+layout.svelte
139
<script>
1410
import { page, navigating, +++updated+++ } from '$app/stores';
1511
</script>
12+
```
1613

17-
<nav>
18-
<a href="/" aria-current={$page.url.pathname === '/'}>
19-
home
20-
</a>
21-
22-
<a href="/about" aria-current={$page.url.pathname === '/about'}>
23-
about
24-
</a>
25-
26-
{#if $navigating}
27-
navigating to {$navigating.to.url.pathname}
28-
{/if}
29-
</nav>
14+
Version changes only happen in production, not during development. For that reason, `$updated` will always be `false` in this tutorial.
3015

31-
<slot />
16+
You can manually check for new versions, regardless of `pollInterval`, by calling `updated.check()`.
3217

33-
+++{#if $updated}
34-
<p class="toast">
35-
A new version of the app is available
18+
```svelte
19+
/// file: src/routes/+layout.svelte
3620
37-
<button on:click={() => location.reload()}>
38-
reload the page
39-
</button>
40-
</p>
41-
{/if}+++
21+
+++{#if $updated}+++
22+
<div class="toast">
23+
<p>
24+
A new version of the app is available
25+
26+
<button on:click={() => location.reload()}>
27+
reload the page
28+
</button>
29+
</p>
30+
</div>
31+
+++{/if}+++
32+
```

content/tutorial/03-sveltekit/08-stores/03-updated-store/app-a/src/routes/+layout.svelte

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { page, navigating, updated } from '$app/stores';
2+
import { page, navigating } from '$app/stores';
33
</script>
44

55
<nav>
@@ -18,12 +18,35 @@
1818

1919
<slot />
2020

21-
{#if $updated}
22-
<p class="toast">
21+
<div class="toast">
22+
<p>
2323
A new version of the app is available
2424

2525
<button on:click={() => location.reload()}>
2626
reload the page
2727
</button>
2828
</p>
29-
{/if}
29+
</div>
30+
31+
<style>
32+
.toast {
33+
position: fixed;
34+
left: 0;
35+
bottom: 0;
36+
width: 100%;
37+
padding: 1rem;
38+
display: flex;
39+
justify-content: center;
40+
gap: 1rem;
41+
}
42+
43+
.toast p {
44+
display: flex;
45+
align-items: center;
46+
gap: 1rem;
47+
background: var(--bg-2);
48+
padding: 0.5rem 0.5rem 0.5rem 1rem;
49+
border-radius: 4px;
50+
}
51+
</style>
52+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script>
2+
import { page, navigating, updated } from '$app/stores';
3+
</script>
4+
5+
<nav>
6+
<a href="/" aria-current={$page.url.pathname === '/'}>
7+
home
8+
</a>
9+
10+
<a href="/about" aria-current={$page.url.pathname === '/about'}>
11+
about
12+
</a>
13+
14+
{#if $navigating}
15+
navigating to {$navigating.to.url.pathname}
16+
{/if}
17+
</nav>
18+
19+
<slot />
20+
21+
{#if $updated}
22+
<div class="toast">
23+
<p>
24+
A new version of the app is available
25+
26+
<button on:click={() => location.reload()}>
27+
reload the page
28+
</button>
29+
</p>
30+
</div>
31+
{/if}
32+
33+
<style>
34+
.toast {
35+
position: fixed;
36+
left: 0;
37+
bottom: 0;
38+
width: 100%;
39+
padding: 1rem;
40+
display: flex;
41+
justify-content: center;
42+
gap: 1rem;
43+
}
44+
45+
.toast p {
46+
display: flex;
47+
align-items: center;
48+
gap: 1rem;
49+
background: var(--bg-2);
50+
padding: 0.5rem 0.5rem 0.5rem 1rem;
51+
border-radius: 4px;
52+
}
53+
</style>
54+

0 commit comments

Comments
 (0)