From a69ce9361612561e47e01d811d7a6ee67d507255 Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Mon, 18 Feb 2019 14:55:23 +0100 Subject: [PATCH] Load plugins sequentially (sorted alphabetically) --- scm-ui/src/containers/PluginLoader.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scm-ui/src/containers/PluginLoader.js b/scm-ui/src/containers/PluginLoader.js index 308f532270..599ffcb67c 100644 --- a/scm-ui/src/containers/PluginLoader.js +++ b/scm-ui/src/containers/PluginLoader.js @@ -34,7 +34,7 @@ class PluginLoader extends React.Component { this.setState({ message: "loading plugin information" }); - + this.getPlugins(this.props.link); } } @@ -55,12 +55,19 @@ class PluginLoader extends React.Component { }); const promises = []; - for (let plugin of plugins) { + const sortedPlugins = plugins.sort(comparePluginsByName); + for (let plugin of sortedPlugins) { promises.push(this.loadPlugin(plugin)); } - return Promise.all(promises); + return promises.reduce((chain, current) => { + return chain.then(chainResults => { + return current.then(currentResult => [...chainResults, currentResult]) + } + ); + }, Promise.resolve([])); }; + loadPlugin = (plugin: Plugin) => { this.setState({ message: `loading ${plugin.name}` @@ -94,7 +101,15 @@ class PluginLoader extends React.Component { return ; } } - +const comparePluginsByName = (a: Plugin, b: Plugin) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; +}; const mapStateToProps = state => { const link = getUiPluginsLink(state); return {