Skip to content

docs:Update App.svelte in Clock example according new rune syntax #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

pochemuto
Copy link
Contributor

Current example doesn't have legacy "$:" syntax. The comment is misleading.

Copy link

vercel bot commented Jan 27, 2025

@pochemuto is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Feb 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
svelte-dev ❌ Failed (Inspect) Feb 18, 2025 7:06pm

@Conduitry
Copy link
Member

Do we want to rework this a bit further and use https://svelte.dev/tutorial/svelte/reactive-builtins instead?

@Rich-Harris
Copy link
Member

We actually don't gain a lot by doing so in this case — the diff looks like this:

<script>
	import { onMount } from 'svelte';
+	import { SvelteDate } from 'svelte/reactivity';

-	let time = $state(new Date());
+	let time = $state(new SvelteDate());

	// these automatically update when `time`
	// changes, because of the `$:` prefix
	let hours = $derived(time.getHours());
	let minutes = $derived(time.getMinutes());
	let seconds = $derived(time.getSeconds());

	onMount(() => {
		const interval = setInterval(() => {
-			time = new Date();
+			time.setTime(Date.now());
		}, 1000);

		return () => {
			clearInterval(interval);
		};
	});
</script>

So I'll merge this as-is — thanks!

@Rich-Harris Rich-Harris merged commit 5dbae29 into sveltejs:main Apr 4, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants