<script>
import { invalidate, invalidable, pinvalidable } from "@macfja/svelte-invalidable"
import { writable } from "svelte/store"
let time = pinvalidable(writable("Never"), () => {
return fetch("https://worldtimeapi.org/api/timezone/Etc/UTC")
.then(r => r.json())
.then(r => r.datetime)
})
const updateTime = () => {
time.invalidate()
}
const updating = time.isUpdating
const values = [2, 7, 3, 5, 11, 13]
let position = 0
let data = invalidable(writable(2), () => values[(++position)%6])
</script>
<p>The last time the date was refresh is: {$time} {#if $updating}(Updating...){/if}</p>
<button id="date-btn" on:click={updateTime}>Do it now</button>
<hr />
<var on:click={() => invalidate(data)}>prime number: {$data}</var>