'use babel'

import {Emitter, CompositeDisposable} from 'atom'
import Validate from './validate'
import Indie from './indie'

export default class IndieRegistry {
  constructor() {
    this.subscriptions = new CompositeDisposable()
    this.emitter = new Emitter()

    this.indieLinters = new Set()
    this.subscriptions.add(this.emitter)
  }

  register(linter) {
    Validate.linter(linter, true)
    const indieLinter = new Indie(linter)

    this.subscriptions.add(indieLinter)
    this.indieLinters.add(indieLinter)

    indieLinter.onDidDestroy(() => {
      this.indieLinters.delete(indieLinter)
    })
    this.emit('observe', indieLinter)

    return indieLinter
  }
  unregister(indieLinter) {
    if (this.indieLinters.has(indieLinter)) {
      indieLinter.dispose()
    }
  }

  // Private method
  observe(callback) {
    this.indieLinters.forEach(callback)
    return this.subscriptions.add('observe', callback)
  }

  dispose() {
    this.subscriptions.dispose()
  }
}

'use babel'

import {Emitter, CompositeDisposable} from 'atom'
import Validate from './validate'
import Indie from './indie'

export default class IndieRegistry {
  constructor() {
    this.subscriptions = new CompositeDisposable()
    this.emitter = new Emitter()

    this.indieLinters = new Set()
    this.subscriptions.add(this.emitter)
  }

  register(linter) {
    Validate.linter(linter, true)
    const indieLinter = new Indie(linter)

    this.subscriptions.add(indieLinter)
    this.indieLinters.add(indieLinter)

    indieLinter.onDidDestroy(() => {
      this.indieLinters.delete(indieLinter)
    })
    indieLinter.onDidUpdateMessages(messages => {
      this.emitter.emit('did-update-messages', {linter: indieLinter, messages})
    })
    this.emit('observe', indieLinter)

    return indieLinter
  }
  unregister(indieLinter) {
    if (this.indieLinters.has(indieLinter)) {
      indieLinter.dispose()
    }
  }

  // Private method
  observe(callback) {
    this.indieLinters.forEach(callback)
    return this.subscriptions.add('observe', callback)
  }
  // Private method
  onDidUpdateMessages(callback) {
    return this.subscriptions.add('did-update-messages', callback)
  }

  dispose() {
    this.subscriptions.dispose()
  }
}

Add onDidUpdateMessages to indie registry