api-client/helpers/network.js

29 lines
902 B
JavaScript
Raw Normal View History

import AxiosStrategy, { cancelRunningAxiosRequest } from "./strategies/AxiosStrategy"
import ExtensionStrategy, {
cancelRunningExtensionRequest,
hasExtensionInstalled,
} from "./strategies/ExtensionStrategy"
export const cancelRunningRequest = (store) => {
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
cancelRunningExtensionRequest()
} else {
cancelRunningAxiosRequest()
}
}
2020-02-20 03:22:42 +00:00
const isExtensionsAllowed = ({ state }) =>
typeof state.postwoman.settings.EXTENSIONS_ENABLED === "undefined" ||
2020-02-24 18:44:50 +00:00
state.postwoman.settings.EXTENSIONS_ENABLED
const runAppropriateStrategy = (req, store) => {
2020-04-08 10:19:13 +00:00
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
return ExtensionStrategy(req, store)
}
2020-02-24 18:44:50 +00:00
return AxiosStrategy(req, store)
}
export const sendNetworkRequest = (req, store) =>
2020-02-24 18:44:50 +00:00
runAppropriateStrategy(req, store).finally(() => window.$nuxt.$loading.finish())