4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 05:06:37 +00:00
AzuraCast/frontend/vue/functions/useRefreshableAsyncState.js
2023-01-07 15:24:18 -06:00

33 lines
730 B
JavaScript

import {useAsyncState} from "@vueuse/core";
import syncOnce from "~/functions/syncOnce";
/**
* Just like useAsyncState, except with settings changed:
* - Does not reset to initial state after every reload
* - Only sets the "loading" ref to true on the initial load, not refreshes
*
* @see useAsyncState
*/
export default function useRefreshableAsyncState(
promise,
initialState,
options = {}
) {
const {state, isLoading: allIsLoading, execute} = useAsyncState(
promise,
initialState,
{
resetOnExecute: false,
...options
}
);
const isLoading = syncOnce(allIsLoading);
return {
state,
isLoading,
execute
};
}