<commit_before>import {DependencyError} from './errors';

export class ModuleManager {
  constructor(app) {
    this.app = app;
    this.currentModule = null;
    this.store = {};
    this.updateMap = {};
  }

  setActiveModule(module) {
    this.currentModule = module;
  }

  reset() {
    this.currentModule = null;
  }

  onDependencyUpdate(depsMap = {}) {
    for (let key in depsMap) {
      if (!this.updateMap[key]) {
        this.updateMap[key] = [depsMap[key]];
      } else {
        this.updateMap[key].push(depsMap[key]);
      }
    }
  }

  addDependency(key, object, config) {
    if (this.store[key] && this.store[key][2].immutable) {
      throw new DependencyError(
        'ModuleManager',
        `Dependency '${key}' is immutable and already used by another module`,
        this.currentModule, this.store[key][1]
      );

      return;
    }

    this.store[key] = [object, this.currentModule, config];

    if (config.alias) {
      Object.defineProperty(this.app, config.alias, {
        get: () => {
          return this.store[key][0];
        },
        set: (value) => {
          if (this.store[key] && this.store[key][2].immutable) {
            throw new DependencyError(
              'ModuleManager',
              `Dependency '${key}' is immutable and already used by another module`,
              this.currentModule, this.store[key][1]
            );

            return;
          }

          this.store[key][0] = value;

          if (this.updateMap[key]) {
            for (let i = 0, max = this.updateMap[key].length; i < max; i++) {
              this.updateMap[key][i](value);
            }
          }
        },
        enumerable: true,
        configurable: true
      });
    }

    if (this.updateMap[key]) {
      for (let i = 0, max = this.updateMap[key].length; i < max; i++) {
        this.updateMap[key][i](object);
      }
    }
  }

  get(key, getModule = false) {
    if (!this.store[key]) {
      throw new DependencyError(
        'ModuleManager',
        `Module requires '${key}' dependency`,
        this.currentModule
      );

      return;
    }

    return getModule ? this.store[key][1] : this.store[key][0];
  }
}<commit_msg>ModuleManager: fix parameter in .addDependency() & add .has() method<commit_after>import {DependencyError} from './errors';

export class ModuleManager {
  constructor(app) {
    this.app = app;
    this.currentModule = null;
    this.store = {};
    this.updateMap = {};
  }

  setActiveModule(module) {
    this.currentModule = module;
  }

  reset() {
    this.currentModule = null;
  }

  onDependencyUpdate(depsMap = {}) {
    for (let key in depsMap) {
      if (!this.updateMap[key]) {
        this.updateMap[key] = [depsMap[key]];
      } else {
        this.updateMap[key].push(depsMap[key]);
      }
    }
  }

  addDependency(key, object, config = {}) {
    if (this.store[key] && this.store[key][2].immutable) {
      throw new DependencyError(
        'ModuleManager',
        `Dependency '${key}' is immutable and already used by another module`,
        this.currentModule, this.store[key][1]
      );

      return;
    }

    this.store[key] = [object, this.currentModule, config];

    if (config.alias) {
      Object.defineProperty(this.app, config.alias, {
        get: () => {
          return this.store[key][0];
        },
        set: (value) => {
          if (this.store[key] && this.store[key][2].immutable) {
            throw new DependencyError(
              'ModuleManager',
              `Dependency '${key}' is immutable and already used by another module`,
              this.currentModule, this.store[key][1]
            );

            return;
          }

          this.store[key][0] = value;

          if (this.updateMap[key]) {
            for (let i = 0, max = this.updateMap[key].length; i < max; i++) {
              this.updateMap[key][i](value);
            }
          }
        },
        enumerable: true,
        configurable: true
      });
    }

    if (this.updateMap[key]) {
      for (let i = 0, max = this.updateMap[key].length; i < max; i++) {
        this.updateMap[key][i](object);
      }
    }
  }

  get(key, getModule = false) {
    if (!this.store[key]) {
      throw new DependencyError(
        'ModuleManager',
        `Module requires '${key}' dependency`,
        this.currentModule
      );

      return;
    }

    return getModule ? this.store[key][1] : this.store[key][0];
  }

  has(key) {
    return Boolean(this.store[key]);
  }
}
{'fraction_non_alphanumeric': 0.14983351831298558, 'fraction_numerical': 0.004439511653718091, 'mean_word_length': 2.0080106809078773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7641627', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1403, 'n_words': 284}