From 4cd60da7b8e1302aa8e4073de3699215af6fbd95 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 22 Mar 2021 15:23:48 +0100 Subject: [PATCH] Fix asyncReactive detection of loading - Removed `success` store as it wouldn't work - We should check for a value in error instead --- ts/sveltelib/async.ts | 7 ++----- ts/sveltelib/asyncReactive.ts | 18 ++++-------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/ts/sveltelib/async.ts b/ts/sveltelib/async.ts index 387dcb3b5..c6af59cc8 100644 --- a/ts/sveltelib/async.ts +++ b/ts/sveltelib/async.ts @@ -1,10 +1,9 @@ -import { Readable, readable, derived } from "svelte/store"; +import { Readable, readable } from "svelte/store"; interface AsyncData { value: Readable; error: Readable; loading: Readable; - success: Readable; } function useAsync(asyncFunction: () => Promise): AsyncData { @@ -22,9 +21,7 @@ function useAsync(asyncFunction: () => Promise): AsyncData set(false)); }); - const success = derived([value], (_, set) => set(true), false); - - return { value, error, loading, success }; + return { value, error, loading }; } export default useAsync; diff --git a/ts/sveltelib/asyncReactive.ts b/ts/sveltelib/asyncReactive.ts index 394acc3a7..2411f9411 100644 --- a/ts/sveltelib/asyncReactive.ts +++ b/ts/sveltelib/asyncReactive.ts @@ -4,7 +4,6 @@ interface AsyncReativeData { value: Readable; error: Readable; loading: Readable; - success: Readable; } function useAsyncReactive( @@ -36,24 +35,15 @@ function useAsyncReactive( ); const loading = derived( - [value, error], - (_, set: (value: boolean) => void) => { - set(false); + promise, + ($promise, set: (value: boolean) => void) => { + $promise?.finally(() => set(false)); return () => set(true); }, true ); - const success = derived( - [value], - (_, set: (value: boolean) => void) => { - set(true); - return () => set(false); - }, - false - ); - - return { value, error, loading, success }; + return { value, error, loading }; } export default useAsyncReactive;