Skip to content

Commit b66e90b

Browse files
author
Rich Harris
committed
updated store
1 parent 47b13ce commit b66e90b

File tree

7 files changed

+92
-1
lines changed

7 files changed

+92
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,40 @@
22
title: updated
33
---
44

5-
> Coming soon
5+
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`.
6+
7+
Version changes only happens 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+
11+
```svelte
12+
/// file: src/routes/+layout.svelte
13+
<script>
14+
import { page, navigating, +++updated+++ } from '$app/stores';
15+
</script>
16+
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>
30+
31+
<slot />
32+
33+
+++{#if $updated}
34+
<p class="toast">
35+
A new version of the app is available
36+
37+
<button on:click={() => location.reload()}>
38+
reload the page
39+
</button>
40+
</p>
41+
{/if}+++
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<p class="toast">
23+
A new version of the app is available
24+
25+
<button on:click={() => location.reload()}>
26+
reload the page
27+
</button>
28+
</p>
29+
{/if}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export async function load() {
2+
return new Promise((fulfil) => {
3+
setTimeout(fulfil, 1000);
4+
});
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>home</h1>
2+
<p>this is the home page.</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export async function load() {
2+
return new Promise((fulfil) => {
3+
setTimeout(fulfil, 1000);
4+
});
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>about</h1>
2+
<p>this is the about page.</p>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
kit: {
3+
version: {
4+
// ideally, this should be something deterministic
5+
// like the output of `git rev-parse HEAD`
6+
name: Date.now().toString(),
7+
8+
// if undefined, no polling will occur
9+
pollInterval: 5000
10+
}
11+
}
12+
};

0 commit comments

Comments
 (0)