Skip to content
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

Confusing two separate parts with the same name #575

Open
bleetube opened this issue Feb 5, 2024 · 0 comments
Open

Confusing two separate parts with the same name #575

bleetube opened this issue Feb 5, 2024 · 0 comments

Comments

@bleetube
Copy link

bleetube commented Feb 5, 2024

I was confused while doing learn.svelte.dev/tutorial/derived-stores:

import { readable, derived } from 'svelte/store';

export const time = readable(new Date(), function start(set) {
	const interval = setInterval(() => {
		set(new Date());
	}, 1000);

	return function stop() {
		clearInterval(interval);
	};
});

const start = new Date();

export const elapsed = derived(
	time,
	($time) => Math.round(($time - start) / 1000)
);

$time has a start function, and $derived uses a start variable initialized thereafter. This duplication seems needless, because afaict either "start" could have been named anything. I would suggest changing one to be named "begin" or something else.

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

No branches or pull requests

1 participant