From 0fccd3d5cb7177574aadae3c00cba270eaa5945d Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sat, 30 May 2020 18:28:13 -0400 Subject: [PATCH] Added cancel request function for network requests --- functions/network.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/functions/network.js b/functions/network.js index c58cc7fd..5b45cc31 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,5 +1,16 @@ -import AxiosStrategy from "./strategies/AxiosStrategy" -import ExtensionStrategy, { hasExtensionInstalled } from "./strategies/ExtensionStrategy" +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" || @@ -13,7 +24,5 @@ const runAppropriateStrategy = (req, store) => { return AxiosStrategy(req, store) } -const sendNetworkRequest = (req, store) => +export const sendNetworkRequest = (req, store) => runAppropriateStrategy(req, store).finally(() => window.$nuxt.$loading.finish()) - -export { sendNetworkRequest }