refresh promise array await "svelte" code example
Example 1: svelte reactive async
let package_name = 'svelte';
let download_count = 0;
$: fetch('https://api.npmjs.org/downloads/point/last-week/' + package_name)
.then(response => response.json())
.then(data => download_count = data.downloads || 0);
Example 2: svelte reactive async
import { writable, derived } from 'svelte/store';
const package_name = writable('svelte');
const download_count = derived(
package_name,
($package_name, set) => {
fetch('https://api.npmjs.org/downloads/point/last-week/' + $package_name)
.then(response => response.json())
.then(data => set(data.downloads));
return () => {
set = () => {}
}
}
);