vue-admin-core
Version:
A Component Library for Vue 3
25 lines (22 loc) • 737 B
JavaScript
import limit from '../../__utils__/limit.mjs';
import subscribe from '../../__utils__/subscribeFocus.mjs';
import { onUnmounted } from 'vue';
const useRefreshOnWindowFocusPlugin = (fetchInstance, { refreshOnWindowFocus, focusTimespan = 5e3 }) => {
let unsubscribe = () => {
};
const stopSubscribe = () => {
unsubscribe == null ? void 0 : unsubscribe();
};
if (refreshOnWindowFocus) {
const limitRefresh = limit(fetchInstance.refresh.bind(fetchInstance), focusTimespan);
unsubscribe = subscribe(() => {
limitRefresh();
});
}
onUnmounted(() => {
stopSubscribe();
});
return {};
};
export { useRefreshOnWindowFocusPlugin as default };
//# sourceMappingURL=useRefreshOnWindowFocusPlugin.mjs.map