About the new updated
from $app/state
#14763
Answered
by
brunnerh
frederikhors
asked this question in
Q&A
-
Right now I'm using this:
<script lang="ts">
import { getStores, page } from '$app/stores';
const { updated } = getStores();
onMount(() => callMe(updated));
</script>
function callMe(updated: Readable<boolean>): Promise<void> {
// other code here
const sw_registration = await navigator.serviceWorker.getRegistration();
// other code here
updated.subscribe(async (value) => {
if (!value) return;
if (sw_registration) {
await sw_registration.update();
} else {
update_app();
}
});
} And this is super useful. Now from But how to use it? Should I use an Another way? |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Dec 18, 2024
Replies: 1 comment
-
You can use import { updated } from '$app/state';
export function watchUpdated() {
$effect(() => {
if (updated.current) {
// do something
}
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
$effect
(and any other rune) in JS/TS files that have.svelte.
in the name, e.g.custom.svelte.ts
.