Loggest thine Stuff
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.
 
 
 
 
 
 

32 lines
686 B

<script lang="ts" context="module">
const contextKey = {ctx: "timeContext"};
interface TimeContextData {
now: Readable<Date>
};
export function getTimeContext() {
return getContext(contextKey) as TimeContextData;
}
</script>
<script lang="ts">
import { writable, type Readable } from "svelte/store";
import { getContext, onMount, setContext } from "svelte";
let nowWritable = writable<Date>(new Date());
setContext<TimeContextData>(contextKey, {
now: nowWritable,
});
onMount(() => {
const interval = setInterval(() => {
nowWritable.set(new Date());
}, 30000)
return () => clearInterval(interval);
})
</script>
<slot></slot>