better code: comments
Massimo Melina committed
Jun 5, 2024 at 09:55 UTC
f6cb5bc67c58b4bc89ae462e471211d83b3497e7
2 files changed
+17
-2
frontend/src/useFetchList.ts
+3
-1
@@ -82,7 +82,9 @@ export default function useFetchList() {
82
if (!Array.isArray(entry)) continue // unexpected
83
const [op, par] = entry
84
const error = op === LIST.error && par
85
- if (error === HTTP_METHOD_NOT_ALLOWED) { // "method not allowed" happens when we try to directly access an unauthorized file, and we get a login prompt, and then get_file_list the file (because we didn't know it was file or folder)
85
+ // "method not allowed" happens when we try to directly access an unauthorized file, and we get a login prompt, and then get_file_list the file (because we didn't know it was file or folder)
86
+ // it also happens accessing a web-page folder, and the reload is the right solution too.
87
+ if (error === HTTP_METHOD_NOT_ALLOWED) {
88
state.messageOnly = t('download_starting', "Your download should now start")
89
window.location.reload() // reload will start the download, because now we got authenticated
90
continue
src/debounceAsync.ts
+14
-1
@@ -2,9 +2,22 @@
2
3
// like lodash.debounce, but also avoids async invocations to overlap
4
export function debounceAsync<Cancelable extends boolean = false, A extends unknown[] = unknown[], R = unknown>(
5
+ // the function you want to not call too often, too soon
6
callback: (...args: A) => Promise<R>,
7
+ // time to wait after invocation of the debounced function. If you call again while waiting, the timer starts again.
8
wait: number=100,
7
- options: { leading?: boolean, maxWait?:number, retain?: number, retainFailure?: number, cancelable?: Cancelable }={}
9
+ options: {
10
+ // in a train of invocations, should we execute also the first one, or just the last one?
11
+ leading?: boolean,
12
+ // since the wait-ing is renewed at each invocation, indefinitely, do you want to put a cap to it?
13
+ maxWait?: number,
14
+ // for how long do you want to cache last success value, and return that at next invocation?
15
+ retain?: number,
16
+ // for how long do you want to cache last failure value, and return that at next invocation?
17
+ retainFailure?: number,
18
+ // should we offer a cancel method to the returned function?
19
+ cancelable?: Cancelable
20
+ } = {}
21
) {
22
type MaybeUndefined<T> = Cancelable extends true ? undefined | T : T
23
type MaybeR = MaybeUndefined<R>