learn.svelte.dev icon indicating copy to clipboard operation
learn.svelte.dev copied to clipboard

Confusing two separate parts with the same name

Open bleetube opened this issue 1 year ago • 0 comments

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.

bleetube avatar Feb 05 '24 21:02 bleetube