2 ms·
Now I notice I was doing: Rip out {#await ...} and put it in the <script> logic, then use local variables when rendering. intuitively and without realizin
by sebastianconcpt 4y ago
Now I notice I was doing:
Rip out {#await ...} and put it in the <script> logic, then use local variables when rendering.
intuitively and without realizing. Thanks for writing about it.
- rsstack 4y agoWe don't use {#await because it has several issues. We use this utility to access promises in Svelte components, converting promises to stores: export type PromiseState<T> = | { status: 'loading'; value?: undefined; error?: undefined } | { status: 'resolved'; value: T; error?: undefined } | { status: 'rejected'; value?: undefined; error: Error }; export function fromPromise<T>(promise: Promise<T>): Readable<PromiseState<T>> { return readable<PromiseState<T>>({ status: 'loading' }, (set) => { void promise .then((value) => set({ status: 'resolved', value })) .catch((error) => set({ status: 'rejected', error })); }); }