'use babel'

/* @flow */

import {CompositeDisposable} from 'atom'
import type {Disposable, TextEditor, TextBuffer, TextEditorGutter} from 'atom'

export class Editor {
  gutter: ?TextEditorGutter;
  textEditor: TextEditor;
  subscriptions: CompositeDisposable;

  constructor(textEditor: TextEditor) {
    this.textEditor = textEditor
    this.subscriptions = new CompositeDisposable()
    const visibility = atom.config.get('linter-ui-default.highlightIssues')
    if (visibility) {
      const position = atom.config.get('linter-ui-default.gutterPosition')
      this.gutter = this.textEditor.addGutter({
        name: 'linter-ui-default',
        priority: position === 'Left' ? -100 : 100
      })
    } else this.gutter = null

  }
  getPath(): string {
    return this.textEditor.getPath()
  }
  getBuffer(): TextBuffer {
    return this.textEditor.getBuffer()
  }
  onDidDestroy(callback: Function): Disposable {
    const subscription = this.textEditor.onDidDestroy(callback)
    this.subscriptions.add(subscription)
    return subscription
  }
  dispose() {
    this.subscriptions.dispose()
    if (this.gutter) {
      this.gutter.destroy()
    }
  }
}

@@ -27,16 +27,17 @@
 import %7B
+ 
 Composit
@@ -47,16 +47,26 @@
 sposable
+, Emitter 
 %7D from '
@@ -84,16 +84,17 @@
 t type %7B
+ 
 Disposab
@@ -137,16 +137,17 @@
 orGutter
+ 
 %7D from '
@@ -204,16 +204,36 @@
 Gutter;%0A
+  emitter: Emitter;%0A
   textEd
@@ -325,24 +325,57 @@
 xtEditor) %7B%0A
+    this.emitter = new Emitter()%0A
     this.tex
@@ -442,24 +442,25 @@
 isposable()%0A
+%0A
     const vi
@@ -800,339 +800,284 @@
 %0A%0A  
-%7D%0A  getPath(): string %7B%0A    return this.textEditor.getPath()%0A  %7D%0A  getBuffer(): TextBuffer %7B%0A    return this.textEditor.getBuffer()%0A  %7D%0A  onDidDestroy(callback: Function): Disposable %7B%0A    const subscription = this.textEditor.onDidDestroy(callback)%0A    this.subscriptions.add(subscription)%0A    return subscription%0A  %7D%0A  dispose() %7B
+  this.subscriptions.add(this.emitter)%0A    this.subscriptions.add(textEditor.onDidDestroy(() =%3E %7B%0A      this.dispose()%0A    %7D))%0A  %7D%0A  onDidDestroy(callback: Function): Disposable %7B%0A    return this.emitter.on('did-destroy')%0A  %7D%0A  dispose() %7B%0A    this.emitter.emit('did-destroy')
 %0A   

Add an emitter to Editor class