api-client/functions/network.js

20 lines
661 B
JavaScript
Raw Normal View History

import AxiosStrategy from "./strategies/AxiosStrategy"
import ExtensionStrategy, { hasExtensionInstalled } from "./strategies/ExtensionStrategy"
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)
}
2020-02-04 19:01:26 +00:00
const sendNetworkRequest = (req, store) =>
2020-02-24 18:44:50 +00:00
runAppropriateStrategy(req, store).finally(() => window.$nuxt.$loading.finish())
2020-02-24 18:44:50 +00:00
export { sendNetworkRequest }