showing results for - "svelte wait"
Evann
15 Sep 2016
1{#await promise}
2	<p>...waiting</p>
3{:then number}
4	<p>The number is {number}</p>
5{:catch error}
6	<p style="color: red">{error.message}</p>
7{/await}
Alina
27 Sep 2019
1let package_name = 'svelte';
2let download_count = 0;
3$: fetch('https://api.npmjs.org/downloads/point/last-week/' + package_name)
4	.then(response => response.json())
5	.then(data => download_count = data.downloads || 0);
6
7// Updating `package_name` will asynchronously update `download_count`
8
Bryony
06 Apr 2020
1import { writable, derived } from 'svelte/store';
2
3const package_name = writable('svelte');
4const download_count = derived(
5	package_name,
6	($package_name, set) => {
7		fetch('https://api.npmjs.org/downloads/point/last-week/' + $package_name)
8			.then(response => response.json())
9			.then(data => set(data.downloads));
10
11		return () => {
12			// We override the `set` function to eliminate race conditions
13			// This does *not* abort running fetch() requests, it only prevents
14			// them from overriding the store.
15			// To learn about canceling fetch requests, search the internet for `AbortController`
16			set = () => {}
17		}
18	}
19);
20
21// Updating `$package_name` will asynchronously update `$download_count`
22