chore: explicit function origin (#2945)

Nothing world changing. I realised recently that I prefer explicitly calling methods of stores and do the same with their states.
Similar to how one would do that with classes.

Since I might make more changes like this in the future (maybe also part of other PRs) I though I'd explain my reasoning here in a bit more detail:

__Benefits__

- saves local mappings, like the `const updateConfig = () => configStore.update()`
- there is no need to look up what exactly is updated, since the function is provide by the store.

__Disadvantages__

- a little bit more verbose (but not thaaat big difference)

---

TLDR: When reading the code this saves the step to check what was mapped.

Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2945
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Co-committed-by: Dominik Pschenitschni <mail@celement.de>
This commit is contained in:
Dominik Pschenitschni 2024-12-18 15:24:42 +00:00 committed by konrad
parent 98be0d6f67
commit f76970b5a3
1 changed files with 5 additions and 6 deletions

View File

@ -51,10 +51,9 @@ export const checkAndSetApiUrl = (url: string | undefined | null): Promise<strin
window.API_URL = urlToCheck.toString()
const configStore = useConfigStore()
const updateConfig = () => configStore.update()
// Check if the api is reachable at the provided url
return updateConfig()
return configStore.update()
.catch(e => {
// Check if it is reachable at /api/v1 and http
if (
@ -63,7 +62,7 @@ export const checkAndSetApiUrl = (url: string | undefined | null): Promise<strin
) {
urlToCheck.pathname = `${urlToCheck.pathname}api/v1`
window.API_URL = urlToCheck.toString()
return updateConfig()
return configStore.update()
}
throw e
})
@ -76,7 +75,7 @@ export const checkAndSetApiUrl = (url: string | undefined | null): Promise<strin
) {
urlToCheck.pathname = `${urlToCheck.pathname}api/v1`
window.API_URL = urlToCheck.toString()
return updateConfig()
return configStore.update()
}
throw e
})
@ -85,7 +84,7 @@ export const checkAndSetApiUrl = (url: string | undefined | null): Promise<strin
if (urlToCheck.port !== API_DEFAULT_PORT) {
urlToCheck.port = API_DEFAULT_PORT
window.API_URL = urlToCheck.toString()
return updateConfig()
return configStore.update()
}
throw e
})
@ -98,7 +97,7 @@ export const checkAndSetApiUrl = (url: string | undefined | null): Promise<strin
) {
urlToCheck.pathname = `${urlToCheck.pathname}api/v1`
window.API_URL = urlToCheck.toString()
return updateConfig()
return configStore.update()
}
throw e
})