From ce76174fac15f2e9c97f9cb6ebe878993b7c946a Mon Sep 17 00:00:00 2001
From: Mateusz Winiarczyk <mateusz.winiarczyk@appunite.com>
Date: Sun, 28 Jan 2024 20:13:02 +0100
Subject: [PATCH] refactor(plugins): remove unnecessary window func

---
 index.d.ts                                    |  3 ---
 src/redux/plugins/plugins.thunk.ts            | 15 ++++++++++++---
 src/redux/root/init.thunks.ts                 |  2 ++
 src/services/pluginsManager/pluginsManager.ts |  1 -
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/index.d.ts b/index.d.ts
index 4e8bc267..248f6f8e 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -15,15 +15,12 @@ type HashPlugin = {
   pluginScript: string;
 };
 
-type SetHashedPlugin = ({ pluginUrl, pluginScript }: HashPlugin) => void;
-
 declare global {
   interface Window {
     minerva: {
       configuration?: MinervaConfiguration;
       plugins: {
         registerPlugin: RegisterPlugin;
-        setHashedPlugin: SetHashedPlugin;
       };
     };
   }
diff --git a/src/redux/plugins/plugins.thunk.ts b/src/redux/plugins/plugins.thunk.ts
index 0b8647d0..a9ab271a 100644
--- a/src/redux/plugins/plugins.thunk.ts
+++ b/src/redux/plugins/plugins.thunk.ts
@@ -50,11 +50,20 @@ export const registerPlugin = createAsyncThunk(
   },
 );
 
-type GetInitPluginsProps = { pluginsId: string[] };
+type GetInitPluginsProps = {
+  pluginsId: string[];
+  setHashedPlugin: ({
+    pluginUrl,
+    pluginScript,
+  }: {
+    pluginUrl: string;
+    pluginScript: string;
+  }) => void;
+};
 
 export const getInitPlugins = createAsyncThunk<void, GetInitPluginsProps>(
   'plugins/getInitPlugins',
-  async ({ pluginsId }): Promise<void> => {
+  async ({ pluginsId, setHashedPlugin }): Promise<void> => {
     /* eslint-disable no-restricted-syntax, no-await-in-loop */
     for (const pluginId of pluginsId) {
       const res = await axiosInstance<Plugin>(apiPath.getPlugin(pluginId));
@@ -65,7 +74,7 @@ export const getInitPlugins = createAsyncThunk<void, GetInitPluginsProps>(
         const { urls } = res.data;
         const scriptRes = await axios(urls[0]);
         const pluginScript = scriptRes.data;
-        window.minerva.plugins.setHashedPlugin({ pluginUrl: urls[0], pluginScript });
+        setHashedPlugin({ pluginUrl: urls[0], pluginScript });
 
         /* eslint-disable no-new-func */
         const loadPlugin = new Function(pluginScript);
diff --git a/src/redux/root/init.thunks.ts b/src/redux/root/init.thunks.ts
index f6adbdc5..a04a5a92 100644
--- a/src/redux/root/init.thunks.ts
+++ b/src/redux/root/init.thunks.ts
@@ -4,6 +4,7 @@ import { PROJECT_ID } from '@/constants';
 import { AppDispatch } from '@/redux/store';
 import { QueryData } from '@/types/query';
 import { getDefaultSearchTab } from '@/components/FunctionalArea/TopBar/SearchBar/SearchBar.utils';
+import { PluginsManager } from '@/services/pluginsManager';
 import { getAllBackgroundsByProjectId } from '../backgrounds/backgrounds.thunks';
 import { getAllPublicOverlaysByProjectId } from '../overlays/overlays.thunks';
 import { getModels } from '../models/models.thunks';
@@ -77,6 +78,7 @@ export const fetchInitialAppData = createAsyncThunk<
     dispatch(
       getInitPlugins({
         pluginsId: queryData.pluginsId,
+        setHashedPlugin: PluginsManager.setHashedPlugin,
       }),
     );
   }
diff --git a/src/services/pluginsManager/pluginsManager.ts b/src/services/pluginsManager/pluginsManager.ts
index d9547782..ab32676f 100644
--- a/src/services/pluginsManager/pluginsManager.ts
+++ b/src/services/pluginsManager/pluginsManager.ts
@@ -15,7 +15,6 @@ export const PluginsManager: PluginsManagerType = {
     window.minerva = {
       plugins: {
         registerPlugin: PluginsManager.registerPlugin,
-        setHashedPlugin: PluginsManager.setHashedPlugin,
       },
     };
 
-- 
GitLab