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.

34 lines
640 B

  1. <script lang="ts" context="module">
  2. const listeners: ((now: Date)=>void)[] = [];
  3. setInterval(() => {
  4. for (const listener of listeners) {
  5. listener(new Date);
  6. }
  7. }, 60000);
  8. </script>
  9. <script lang="ts">
  10. import { onMount } from "svelte";
  11. export let now: Date | number;
  12. function onMinute(date: Date) {
  13. if (typeof(now) === "number") {
  14. now = date.getTime();
  15. } else {
  16. now = date;
  17. }
  18. }
  19. onMount(() => {
  20. listeners.push(onMinute);
  21. return () => {
  22. const index = listeners.indexOf(onMinute);
  23. if (index !== -1) {
  24. listeners.splice(index, 1);
  25. }
  26. }
  27. })
  28. </script>