'use babel';

import {Emitter} from 'atom';
import Project from './project';

export default class Projects {
  constructor(db=null) {
    this.emitter = new Emitter();
    this.db = db;

    this.db.onUpdate(() => this.emitter.emit('projects-updated'));
  }

  onUpdate(callback) {
    this.emitter.on('projects-updated', callback);
  }

  getAll(callback) {
    this.db.find(projectSettings => {
      let projects = [];
      let setting;
      let project;
      let key;
      for (key in projectSettings) {
        setting = projectSettings[key];
        if (setting.paths) {
          project = new Project(setting, this.db);
          projects.push(project);
        }
      }

      callback(projects);
    });
  }

  getCurrent(callback) {
    this.getAll(projects => {
      projects.forEach(project => {
        if (project.isCurrent()) {
          callback(project);
        }
      });
    });
  }
}

'use babel';

import {Emitter} from 'atom';
import Project from './project';

export default class Projects {
  constructor(db=null) {
    this.emitter = new Emitter();
    this.db = db;

    this.db.addUpdater(null, {}, () => this.emitter.emit('projects-updated'));
  }

  onUpdate(callback) {
    this.emitter.on('projects-updated', callback);
  }

  getAll(callback) {
    this.db.find(projectSettings => {
      let projects = [];
      let setting;
      let project;
      let key;
      for (key in projectSettings) {
        setting = projectSettings[key];
        if (setting.paths) {
          project = new Project(setting, this.db);
          projects.push(project);
        }
      }

      callback(projects);
    });
  }

  getCurrent(callback) {
    this.getAll(projects => {
      projects.forEach(project => {
        if (project.isCurrent()) {
          callback(project);
        }
      });
    });
  }
}

Update to use addUpdater instead of onUpdate on db
Update to use addUpdater instead of onUpdate on db
