learn.svelte.dev
learn.svelte.dev copied to clipboard
Confusing two separate parts with the same name
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.