forked from mirrors/homebox
fix: prevent resetting dialog state on error (#524)
Former-commit-id: 8c7d91ea52
This commit is contained in:
parent
a2479155b2
commit
0de6c2338d
2 changed files with 38 additions and 7 deletions
19
frontend/composables/use-defer.ts
Normal file
19
frontend/composables/use-defer.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
type DeferFunction<TArgs extends any[], TReturn> = (...args: TArgs) => TReturn;
|
||||
|
||||
// useDefer is a function that takes a function and returns a function that
|
||||
// calls the original function and then calls the onComplete function.
|
||||
export function useDefer<TArgs extends any[], TReturn>(
|
||||
onComplete: (...args: TArgs) => void,
|
||||
func: DeferFunction<TArgs, TReturn>
|
||||
): DeferFunction<TArgs, TReturn> {
|
||||
return (...args: TArgs) => {
|
||||
let result: TReturn;
|
||||
try {
|
||||
result = func(...args);
|
||||
} finally {
|
||||
onComplete(...args);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue