You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
640 B

<script lang="ts" context="module">
const listeners: ((now: Date)=>void)[] = [];
setInterval(() => {
for (const listener of listeners) {
listener(new Date);
}
}, 60000);
</script>
<script lang="ts">
import { onMount } from "svelte";
export let now: Date | number;
function onMinute(date: Date) {
if (typeof(now) === "number") {
now = date.getTime();
} else {
now = date;
}
}
onMount(() => {
listeners.push(onMinute);
return () => {
const index = listeners.indexOf(onMinute);
if (index !== -1) {
listeners.splice(index, 1);
}
}
})
</script>