<commit_before>"use babel";

import { CompositeDisposable, Disposable } from 'atom';
import path from 'path';
import PackagesListView from './packages-list-view';
import reloadPackage from './reload-package';
import PackageWatcher from './package-wacher';
import StatusBarManager from './status-bar-manager';

export default class AtomHotPackageLoader {
  constructor() {
    this.subscriptions = null;
    this.watcher = null;
    this.packagesListView = null;
    this.targetPackageName = null;
  }

  activate(state) {
    this.subscriptions = new CompositeDisposable();
    this.packageWatcher = new PackageWatcher();
    this.packagesListView = new PackagesListView();
    this.packagesListView.emitter.on('did-confirm', (packageName) => {
      this.targetPackageName = packageName;
      this.statusBarManager.update('target', this.targetPackageName);
    });
    this.statusBarManager = new StatusBarManager();

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'atom-hot-package-loader:reload': () => {
        if (this.targetPackageName) {
          reloadPackage(this.targetPackageName, true)
        } else {
          this.showNotificationForSelectPackage();
        }
      },
      'atom-hot-package-loader:watch': () => {
        if (this.targetPackageName) {
          this.statusBarManager.update('wathing', this.targetPackageName);
          this.packageWatcher.watch(this.targetPackageName);
        } else {
          this.showNotificationForSelectPackage();
        }
      },
      'atom-hot-package-loader:unwatch': () => {
        this.packageWatcher.unwatch();
        this.statusBarManager.update('target', this.targetPackageName);
      },
      'atom-hot-package-loader:select-package': () => {
        this.packagesListView.toggle();
      },
    }));
  }

  consumeStatusBar(statusBar) {
    this.statusBarManager.initialize(statusBar);
    this.statusBarManager.attach();
  }

  showNotificationForSelectPackage() {
    atom.notifications.addWarning('Please select package by using `atom-hot-package-loader:select-package`');
  }

  deactivate() {
    this.subscriptions.dispose();
    if (this.statusBarManager) {
      this.statusBarManager.detach();
    }
  }
}<commit_msg>Refactor package commands into functions.<commit_after>"use babel";

import { CompositeDisposable, Disposable } from 'atom';
import path from 'path';
import PackagesListView from './packages-list-view';
import reloadPackage from './reload-package';
import PackageWatcher from './package-wacher';
import StatusBarManager from './status-bar-manager';

function getConfig(name) {
  return atom.config.get(`atom-hot-package-loader.${name}`);
}

export default class AtomHotPackageLoader {
  constructor() {
    this.subscriptions = null;
    this.watcher = null;
    this.packagesListView = null;
    this.targetPackageName = null;
  }

  activate(state) {
    this.subscriptions = new CompositeDisposable();
    this.packageWatcher = new PackageWatcher();
    this.packagesListView = new PackagesListView();
    this.packagesListView.emitter.on('did-confirm', (packageName) => {
      this.setTargetPackage(packageName);
    });
    this.statusBarManager = new StatusBarManager();

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'atom-hot-package-loader:reload': this.reload.bind(this),
      'atom-hot-package-loader:watch': this.watch.bind(this),
      'atom-hot-package-loader:unwatch': this.unwatch.bind(this),
      'atom-hot-package-loader:select-package': () => {
        this.packagesListView.toggle();
      },
    }));
  }

  consumeStatusBar(statusBar) {
    this.statusBarManager.initialize(statusBar);
    this.statusBarManager.attach();
  }

  setTargetPackage(packageName) {
    this.targetPackageName = packageName;
    this.statusBarManager.update('target', this.targetPackageName);
  }

  reload() {
    if (this.targetPackageName) {
      reloadPackage(this.targetPackageName);
    } else {
      this.showNotificationForSelectPackage();
    }
  }

  watch() {
    if (this.targetPackageName) {
      this.statusBarManager.update('watching', this.targetPackageName);
      this.packageWatcher.watch(this.targetPackageName);
    } else {
      this.showNotificationForSelectPackage();
    }
  }

  unwatch() {
    this.packageWatcher.unwatch();
    this.statusBarManager.update('target', this.targetPackageName);
  }

  showNotificationForSelectPackage() {
    atom.notifications.addWarning('Please select package by using `atom-hot-package-loader:select-package`');
  }

  deactivate() {
    this.subscriptions.dispose();
    if (this.statusBarManager) {
      this.statusBarManager.detach();
    }
  }
}
{'fraction_non_alphanumeric': 0.13289107639631928, 'fraction_numerical': 0.0, 'mean_word_length': 3.5958702064896757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '3078182', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1341, 'n_words': 207}