Remove pending, and resort to checking for value
- once value is set, it won't be unset
This commit is contained in:
parent
b3851172ba
commit
6d546b0bca
@ -15,7 +15,7 @@
|
|||||||
export let initialDays: number;
|
export let initialDays: number;
|
||||||
export let controller: SvelteComponent | null;
|
export let controller: SvelteComponent | null;
|
||||||
|
|
||||||
const browserSearch = (search: string, query: string) => {
|
const browserSearch = (search: string, query: string): void => {
|
||||||
bridgeCommand(`browserSearch:${search} ${query}`);
|
bridgeCommand(`browserSearch:${search} ${query}`);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -34,7 +34,6 @@
|
|||||||
{initialDays}
|
{initialDays}
|
||||||
let:search
|
let:search
|
||||||
let:days
|
let:days
|
||||||
let:pending
|
|
||||||
let:loading
|
let:loading
|
||||||
let:sourceData
|
let:sourceData
|
||||||
let:preferences
|
let:preferences
|
||||||
@ -43,7 +42,7 @@
|
|||||||
<svelte:component this={controller} {i18n} {search} {days} {loading} />
|
<svelte:component this={controller} {i18n} {search} {days} {loading} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if !pending}
|
{#if sourceData && preferences && revlogRange}
|
||||||
{#each graphs as graph}
|
{#each graphs as graph}
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={graph}
|
this={graph}
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
const days = writable(initialDays);
|
const days = writable(initialDays);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
pending: graphPending,
|
|
||||||
loading: graphLoading,
|
loading: graphLoading,
|
||||||
|
error: graphError,
|
||||||
value: graphValue,
|
value: graphValue,
|
||||||
} = useAsyncReactive(() => getGraphData($search, $days), [
|
} = useAsyncReactive(() => getGraphData($search, $days), [
|
||||||
search,
|
search,
|
||||||
@ -24,19 +24,30 @@
|
|||||||
|
|
||||||
const preferencesPromise = getPreferences();
|
const preferencesPromise = getPreferences();
|
||||||
const {
|
const {
|
||||||
pending: prefsPending,
|
|
||||||
loading: prefsLoading,
|
loading: prefsLoading,
|
||||||
|
error: prefsError,
|
||||||
value: prefsValue,
|
value: prefsValue,
|
||||||
} = useAsync(() => preferencesPromise);
|
} = useAsync(() => preferencesPromise);
|
||||||
|
|
||||||
$: revlogRange = daysToRevlogRange($days);
|
$: revlogRange = daysToRevlogRange($days);
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($graphError) {
|
||||||
|
alert($graphError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($prefsError) {
|
||||||
|
alert($prefsError)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot
|
<slot
|
||||||
{search}
|
{search}
|
||||||
{days}
|
{days}
|
||||||
{revlogRange}
|
{revlogRange}
|
||||||
pending={$graphPending || $prefsPending}
|
|
||||||
loading={$graphLoading || $prefsLoading}
|
loading={$graphLoading || $prefsLoading}
|
||||||
sourceData={$graphValue}
|
sourceData={$graphValue}
|
||||||
preferences={$prefsValue} />
|
preferences={$prefsValue} />
|
||||||
|
@ -3,7 +3,7 @@ import { Readable, readable, derived } from "svelte/store";
|
|||||||
interface AsyncData<T, E> {
|
interface AsyncData<T, E> {
|
||||||
value: Readable<T | null>;
|
value: Readable<T | null>;
|
||||||
error: Readable<E | null>;
|
error: Readable<E | null>;
|
||||||
pending: Readable<boolean>;
|
loading: Readable<boolean>;
|
||||||
success: Readable<boolean>;
|
success: Readable<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,13 +18,13 @@ function useAsync<T, E = unknown>(asyncFunction: () => Promise<T>): AsyncData<T,
|
|||||||
promise.catch((value: E) => set(value));
|
promise.catch((value: E) => set(value));
|
||||||
});
|
});
|
||||||
|
|
||||||
const pending = readable(true, (set: (value: boolean) => void) => {
|
const loading = readable(true, (set: (value: boolean) => void) => {
|
||||||
promise.finally(() => set(false));
|
promise.finally(() => set(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = derived([value], (_, set) => set(true), false);
|
const success = derived([value], (_, set) => set(true), false);
|
||||||
|
|
||||||
return { value, error, pending, success };
|
return { value, error, loading, success };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useAsync;
|
export default useAsync;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { Readable, readable, derived } from "svelte/store";
|
import { Readable, derived } from "svelte/store";
|
||||||
|
|
||||||
interface AsyncReativeData<T, E> {
|
interface AsyncReativeData<T, E> {
|
||||||
value: Readable<T | null>;
|
value: Readable<T | null>;
|
||||||
error: Readable<E | null>;
|
error: Readable<E | null>;
|
||||||
pending: Readable<boolean>;
|
|
||||||
loading: Readable<boolean>;
|
loading: Readable<boolean>;
|
||||||
success: Readable<boolean>;
|
success: Readable<boolean>;
|
||||||
}
|
}
|
||||||
@ -17,7 +16,7 @@ function useAsyncReactive<T, E>(
|
|||||||
|
|
||||||
const value = derived(
|
const value = derived(
|
||||||
promise,
|
promise,
|
||||||
($promise, set: (value: T | null) => void) => {
|
($promise, set: (value: T) => void) => {
|
||||||
$promise.then((value: T) => set(value));
|
$promise.then((value: T) => set(value));
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
@ -32,10 +31,6 @@ function useAsyncReactive<T, E>(
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
const pending = readable(true, (set: (value: boolean) => void) => {
|
|
||||||
initial.finally(() => set(false));
|
|
||||||
});
|
|
||||||
|
|
||||||
const loading = derived(
|
const loading = derived(
|
||||||
[value, error],
|
[value, error],
|
||||||
(_, set: (value: boolean) => void) => {
|
(_, set: (value: boolean) => void) => {
|
||||||
@ -54,7 +49,7 @@ function useAsyncReactive<T, E>(
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
return { value, error, pending, loading, success };
|
return { value, error, loading, success };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useAsyncReactive;
|
export default useAsyncReactive;
|
||||||
|
Loading…
Reference in New Issue
Block a user