From 6d546b0bca673c9a2bb4a1979324ee328bd92ba7 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 22 Mar 2021 00:40:19 +0100 Subject: [PATCH] Remove pending, and resort to checking for value - once value is set, it won't be unset --- ts/graphs/GraphsPage.svelte | 5 ++--- ts/graphs/WithGraphData.svelte | 17 ++++++++++++++--- ts/graphs/async.ts | 6 +++--- ts/graphs/asyncReactive.ts | 11 +++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index c76236bb1..90f8a2c1f 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -15,7 +15,7 @@ export let initialDays: number; export let controller: SvelteComponent | null; - const browserSearch = (search: string, query: string) => { + const browserSearch = (search: string, query: string): void => { bridgeCommand(`browserSearch:${search} ${query}`); }; @@ -34,7 +34,6 @@ {initialDays} let:search let:days - let:pending let:loading let:sourceData let:preferences @@ -43,7 +42,7 @@ {/if} - {#if !pending} + {#if sourceData && preferences && revlogRange} {#each graphs as graph} getGraphData($search, $days), [ search, @@ -24,19 +24,30 @@ const preferencesPromise = getPreferences(); const { - pending: prefsPending, loading: prefsLoading, + error: prefsError, value: prefsValue, } = useAsync(() => preferencesPromise); $: revlogRange = daysToRevlogRange($days); + + $: { + if ($graphError) { + alert($graphError) + } + } + + $: { + if ($prefsError) { + alert($prefsError) + } + } diff --git a/ts/graphs/async.ts b/ts/graphs/async.ts index 8037a7e24..387dcb3b5 100644 --- a/ts/graphs/async.ts +++ b/ts/graphs/async.ts @@ -3,7 +3,7 @@ import { Readable, readable, derived } from "svelte/store"; interface AsyncData { value: Readable; error: Readable; - pending: Readable; + loading: Readable; success: Readable; } @@ -18,13 +18,13 @@ function useAsync(asyncFunction: () => Promise): AsyncData set(value)); }); - const pending = readable(true, (set: (value: boolean) => void) => { + const loading = readable(true, (set: (value: boolean) => void) => { promise.finally(() => set(false)); }); const success = derived([value], (_, set) => set(true), false); - return { value, error, pending, success }; + return { value, error, loading, success }; } export default useAsync; diff --git a/ts/graphs/asyncReactive.ts b/ts/graphs/asyncReactive.ts index 57d7b500f..70dfcdfd9 100644 --- a/ts/graphs/asyncReactive.ts +++ b/ts/graphs/asyncReactive.ts @@ -1,9 +1,8 @@ -import { Readable, readable, derived } from "svelte/store"; +import { Readable, derived } from "svelte/store"; interface AsyncReativeData { value: Readable; error: Readable; - pending: Readable; loading: Readable; success: Readable; } @@ -17,7 +16,7 @@ function useAsyncReactive( const value = derived( promise, - ($promise, set: (value: T | null) => void) => { + ($promise, set: (value: T) => void) => { $promise.then((value: T) => set(value)); }, null @@ -32,10 +31,6 @@ function useAsyncReactive( null ); - const pending = readable(true, (set: (value: boolean) => void) => { - initial.finally(() => set(false)); - }); - const loading = derived( [value, error], (_, set: (value: boolean) => void) => { @@ -54,7 +49,7 @@ function useAsyncReactive( false ); - return { value, error, pending, loading, success }; + return { value, error, loading, success }; } export default useAsyncReactive;