fix(plugins): multiple plugins (MIN-284)
Added the ability to load multiple instances of the same plugin. A mechanism for adding a number to the plugin name has been added when a given plugin is already loaded and we load another instance of the same plugin. If we do not have a plugin loaded without a prefix/without a number next to the name, the next instance will be loaded as such without a prefix/number. For example, we have 3 instances of the same plugin loaded, so we have the name "plugin", "plugin (1)", "plugin (2)". If we remove the "plugin" instance, the next loaded instance will be named "plugin" and not "plugin (3)".
Why mechanism of getting number is handled by storing occurrences in plugins manager and not taking active plugins from redux?
When we load many plugins at once, e.g. when entering the url where the plugin hashes are, many scripts are launched at once in getInitPlugins
, we invoke the script, but we have no way of tracking/controlling when PluginsManager.registerPlugin
and store.dispatch(registerPlugin)
are called and completed in it, therefore there is a race condition and if we took the number of loaded plugins from the store, e.g. several plugins could take the same number and therefore several plugins would have e.g. number 2 in their name. This is why we handle it in PluginsManager.registerPlugin
as saving hashes as a hashMap synchronously, we can track the number of loaded plugins bypassing the race condition.
Closes MIN-284
Merge request reports
Activity
assigned to @mateusz-winiarczyk
30 24 ); 31 25 32 const handleSetCurrentDrawerPluginHash = (hash: string): void => { 33 dispatch(setCurrentDrawerPluginHash(hash)); 34 }; 35 36 26 const handleLoadPlugin = async (): Promise<void> => { 37 27 try { 38 28 setIsLoading(true); 39 29 const response = await axios(pluginUrl); 40 30 let pluginScript = response.data; 41 31 42 const hash = PluginsManager.setHashedPlugin({ 32 PluginsManager.setHashedPlugin({ 43 33 pluginUrl, 44 34 pluginScript, 49 39 /* eslint-disable no-new-func */ 50 40 const loadPlugin = new Function(pluginScript); 51 41 52 if (!(hash in activePlugins)) { 53 loadPlugin(); 54 } 42 loadPlugin(); This blocked the ability to load multiple instances of one plugin, so it had to be removed, and we don't need to block it anymore
Edited by mateusz-winiarczyk
added 12 commits
-
cc3308b9...59979c47 - 10 commits from branch
development
- 130c1ee1 - Merge remote-tracking branch 'origin/development' into MIN-284-multiple-plugins
- b6f89a54 - Merge remote-tracking branch 'origin/development' into MIN-284-multiple-plugins
-
cc3308b9...59979c47 - 10 commits from branch
mentioned in commit 6bb92217