<commit_before>import {EventEmitter} from "events";

import AppDispatcher from "../AppDispatcher";
import PluginDispatcher from "../plugin/PluginDispatcher";
import DialogActions from "../actions/DialogActions";
import DialogSeverity from "../constants/DialogSeverity";
import PluginActions from "../actions/PluginActions";
import PluginEvents from "../events/PluginEvents";

import Util from "../helpers/Util";

var pluginsMetaData = [];
var pluginsToLoad = [];
var pluginsStarted = [];
var pluginsErrored = [];

var bootstrapComplete = false;

function loadNextPlugin() {
  if (pluginsToLoad.length === 0) {
    return;
  }
  PluginActions.requestPlugin(pluginsToLoad.shift());
}

var PluginStore = Util.extendObject(EventEmitter.prototype, {
  bootstrap: function () {
    PluginActions.requestMetaInfo();
  },
  isBootstrapComplete: function () {
    return bootstrapComplete;
  }
});

PluginDispatcher.register(function (event) {
  switch (event.eventType) {
    case "STARTUP_COMPLETE":
      pluginsStarted.push(event.pluginId);

      let allStarted = pluginsMetaData.every(plugin => {
        return pluginsStarted.includes(plugin.id);
      });

      if (allStarted) {
        bootstrapComplete = true;
        PluginStore.emit(PluginEvents.BOOTSTRAP_COMPLETE);
      }
      break;
  }
});

AppDispatcher.register(function (action) {
  switch (action.actionType) {
    case PluginEvents.META_INFO_SUCCESS:
      pluginsMetaData = action.data;
      pluginsToLoad = Util.deepCopy(pluginsMetaData);
      loadNextPlugin();
      break;
    case PluginEvents.REQUEST_SUCCESS:
      pluginsLoaded.push(action.metaInfo);
      loadNextPlugin();
      break;
    case PluginEvents.REQUEST_ERROR:
      pluginsErrored.push(action.metaInfo);
      DialogActions.alert({
        title: `Could not load plugin`,
        message: `${action.metaInfo.name} (${action.metaInfo.hash})`,
        severity: DialogSeverity.WARNING
      });
      loadNextPlugin();
      break;
  }
});

export default PluginStore;
<commit_msg>Take errored plugins into startup complete<commit_after>import {EventEmitter} from "events";

import AppDispatcher from "../AppDispatcher";
import PluginDispatcher from "../plugin/PluginDispatcher";
import DialogActions from "../actions/DialogActions";
import DialogSeverity from "../constants/DialogSeverity";
import PluginActions from "../actions/PluginActions";
import PluginEvents from "../events/PluginEvents";

import Util from "../helpers/Util";

var pluginsMetaData = [];
var pluginsToLoad = [];
var pluginsStarted = [];
var pluginsErrored = [];

var bootstrapComplete = false;

function loadNextPlugin() {
  if (pluginsToLoad.length === 0) {
    return;
  }
  PluginActions.requestPlugin(pluginsToLoad.shift());
}

function checkForStartupCompleteAndEmit() {
  let allStarted = pluginsMetaData.every(plugin => {
    return pluginsStarted.includes(plugin.id) ||
      pluginsErrored.some(errored => errored.id === plugin.id);
  });

  if (allStarted) {
    bootstrapComplete = true;
    PluginStore.emit(PluginEvents.BOOTSTRAP_COMPLETE);
  }
}

var PluginStore = Util.extendObject(EventEmitter.prototype, {
  bootstrap: function () {
    PluginActions.requestMetaInfo();
  },
  isBootstrapComplete: function () {
    return bootstrapComplete;
  }
});

PluginDispatcher.register(function (event) {
  switch (event.eventType) {
    case "STARTUP_COMPLETE":
      pluginsStarted.push(event.pluginId);
      checkForStartupCompleteAndEmit();
      break;
  }
});

AppDispatcher.register(function (action) {
  switch (action.actionType) {
    case PluginEvents.META_INFO_SUCCESS:
      pluginsMetaData = action.data;
      pluginsToLoad = Util.deepCopy(pluginsMetaData);
      loadNextPlugin();
      break;
    case PluginEvents.REQUEST_SUCCESS:
      pluginsLoaded.push(action.metaInfo);
      loadNextPlugin();
      break;
    case PluginEvents.REQUEST_ERROR:
      pluginsErrored.push(action.metaInfo);
      checkForStartupCompleteAndEmit();
      DialogActions.alert({
        title: `Could not load plugin`,
        message: `${action.metaInfo.name} (${action.metaInfo.hash})`,
        severity: DialogSeverity.WARNING
      });
      loadNextPlugin();
      break;
  }
});

export default PluginStore;

{'fraction_non_alphanumeric': 0.1204250295159386, 'fraction_numerical': 0.0004722550177095632, 'mean_word_length': 3.852233676975945, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1853936', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1194, 'n_words': 240}