Skip to content

Commit

Permalink
add something to do on updated-store tutorial (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Rich Harris <rich.harris@vercel.com>
  • Loading branch information
Rich-Harris and Rich-Harris authored Dec 15, 2023
1 parent 7eac90f commit 3c3af89
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 30 deletions.
43 changes: 17 additions & 26 deletions content/tutorial/03-sveltekit/08-stores/03-updated-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@ title: updated

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`.

Version changes only happen in production, not during development. For that reason, `$updated` will always be `false` in this tutorial.

You can manually check for new versions, regardless of `pollInterval`, by calling `updated.check()`.

```svelte
/// file: src/routes/+layout.svelte
<script>
import { page, navigating, +++updated+++ } from '$app/stores';
</script>
```

<nav>
<a href="/" aria-current={$page.url.pathname === '/'}>
home
</a>
<a href="/about" aria-current={$page.url.pathname === '/about'}>
about
</a>
{#if $navigating}
navigating to {$navigating.to.url.pathname}
{/if}
</nav>
Version changes only happen in production, not during development. For that reason, `$updated` will always be `false` in this tutorial.

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

+++{#if $updated}
<p class="toast">
A new version of the app is available
```svelte
/// file: src/routes/+layout.svelte
<button on:click={() => location.reload()}>
reload the page
</button>
</p>
{/if}+++
+++{#if $updated}+++
<div class="toast">
<p>
A new version of the app is available
<button on:click={() => location.reload()}>
reload the page
</button>
</p>
</div>
+++{/if}+++
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { page, navigating, updated } from '$app/stores';
import { page, navigating } from '$app/stores';
</script>

<nav>
Expand All @@ -18,12 +18,35 @@

<slot />

{#if $updated}
<p class="toast">
<div class="toast">
<p>
A new version of the app is available

<button on:click={() => location.reload()}>
reload the page
</button>
</p>
{/if}
</div>

<style>
.toast {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
padding: 1rem;
display: flex;
justify-content: center;
gap: 1rem;
}
.toast p {
display: flex;
align-items: center;
gap: 1rem;
background: var(--bg-2);
padding: 0.5rem 0.5rem 0.5rem 1rem;
border-radius: 4px;
}
</style>

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>
import { page, navigating, updated } from '$app/stores';
</script>

<nav>
<a href="/" aria-current={$page.url.pathname === '/'}>
home
</a>

<a href="/about" aria-current={$page.url.pathname === '/about'}>
about
</a>

{#if $navigating}
navigating to {$navigating.to.url.pathname}
{/if}
</nav>

<slot />

{#if $updated}
<div class="toast">
<p>
A new version of the app is available

<button on:click={() => location.reload()}>
reload the page
</button>
</p>
</div>
{/if}

<style>
.toast {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
padding: 1rem;
display: flex;
justify-content: center;
gap: 1rem;
}
.toast p {
display: flex;
align-items: center;
gap: 1rem;
background: var(--bg-2);
padding: 0.5rem 0.5rem 0.5rem 1rem;
border-radius: 4px;
}
</style>

1 comment on commit 3c3af89

@vercel
Copy link

@vercel vercel bot commented on 3c3af89 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.