aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/react.tsx13
-rw-r--r--src/utils/types.ts2
2 files changed, 13 insertions, 2 deletions
diff --git a/src/utils/react.tsx b/src/utils/react.tsx
index 69c1df2..a4c7152 100644
--- a/src/utils/react.tsx
+++ b/src/utils/react.tsx
@@ -67,6 +67,7 @@ interface AwaiterOpts<T> {
fallbackValue: T;
deps?: unknown[];
onError?(e: any): void;
+ onSuccess?(value: T): void;
}
/**
* Await a promise
@@ -94,8 +95,16 @@ export function useAwaiter<T>(factory: () => Promise<T>, providedOpts?: AwaiterO
if (!state.pending) setState({ ...state, pending: true });
factory()
- .then(value => isAlive && setState({ value, error: null, pending: false }))
- .catch(error => isAlive && (setState({ value: null, error, pending: false }), opts.onError?.(error)));
+ .then(value => {
+ if (!isAlive) return;
+ setState({ value, error: null, pending: false });
+ opts.onSuccess?.(value);
+ })
+ .catch(error => {
+ if (!isAlive) return;
+ setState({ value: null, error, pending: false });
+ opts.onError?.(error);
+ });
return () => void (isAlive = false);
}, opts.deps);
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 5c7a85c..c81b13a 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -277,6 +277,8 @@ export interface DefinedSettings<D extends SettingsDefinition = SettingsDefiniti
* will be an empty string until plugin is initialized
*/
pluginName: string;
+
+ withPrivateSettings<T>(): this & { store: T; };
}
export type PartialExcept<T, R extends keyof T> = Partial<T> & Required<Pick<T, R>>;