Isolate Netlify, Firebase and Helper functions + Import from absolute paths
This commit is contained in:
28
helpers/network.js
Normal file
28
helpers/network.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import AxiosStrategy, { cancelRunningAxiosRequest } from "./strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
} from "./strategies/ExtensionStrategy"
|
||||
|
||||
export const cancelRunningRequest = (store) => {
|
||||
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
|
||||
cancelRunningExtensionRequest()
|
||||
} else {
|
||||
cancelRunningAxiosRequest()
|
||||
}
|
||||
}
|
||||
|
||||
const isExtensionsAllowed = ({ state }) =>
|
||||
typeof state.postwoman.settings.EXTENSIONS_ENABLED === "undefined" ||
|
||||
state.postwoman.settings.EXTENSIONS_ENABLED
|
||||
|
||||
const runAppropriateStrategy = (req, store) => {
|
||||
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
|
||||
return ExtensionStrategy(req, store)
|
||||
}
|
||||
|
||||
return AxiosStrategy(req, store)
|
||||
}
|
||||
|
||||
export const sendNetworkRequest = (req, store) =>
|
||||
runAppropriateStrategy(req, store).finally(() => window.$nuxt.$loading.finish())
|
||||
Reference in New Issue
Block a user