mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
Add type signatures to asyncReactive
This commit is contained in:
parent
6ec721d550
commit
a418d36c7f
1 changed files with 6 additions and 6 deletions
|
@ -12,14 +12,14 @@ function useAsyncReactive<T, E>(
|
||||||
): AsyncReativeData<T, E> {
|
): AsyncReativeData<T, E> {
|
||||||
const promise = derived(
|
const promise = derived(
|
||||||
dependencies,
|
dependencies,
|
||||||
(_, set: (value: Promise<T> | null) => void) => set(asyncFunction()),
|
(_, set: (value: Promise<T> | null) => void): void => set(asyncFunction()),
|
||||||
// initialize with null to avoid duplicate fetch on init
|
// initialize with null to avoid duplicate fetch on init
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
const value = derived(
|
const value = derived(
|
||||||
promise,
|
promise,
|
||||||
($promise, set: (value: T) => void) => {
|
($promise, set: (value: T) => void): void => {
|
||||||
$promise?.then((value: T) => set(value));
|
$promise?.then((value: T) => set(value));
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
|
@ -27,18 +27,18 @@ function useAsyncReactive<T, E>(
|
||||||
|
|
||||||
const error = derived(
|
const error = derived(
|
||||||
promise,
|
promise,
|
||||||
($promise, set: (error: E | null) => void) => {
|
($promise, set: (error: E | null) => void): (() => void) => {
|
||||||
$promise?.catch((error: E) => set(error));
|
$promise?.catch((error: E) => set(error));
|
||||||
return () => set(null);
|
return (): void => set(null);
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
const loading = derived(
|
const loading = derived(
|
||||||
promise,
|
promise,
|
||||||
($promise, set: (value: boolean) => void) => {
|
($promise, set: (value: boolean) => void): (() => void) => {
|
||||||
$promise?.finally(() => set(false));
|
$promise?.finally(() => set(false));
|
||||||
return () => set(true);
|
return (): void => set(true);
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue