+{CompositeDisposable} = require 'atom'
 _ = require 'lodash'
 
 class AnalysisDecorator
   constructor: (@errors) ->
+    @subscriptions = new CompositeDisposable()
     @listen()
 
   listen: =>
-    atom.workspace.observeTextEditors @handleEditors
-    @errors.onChange @handleErrors
+    @subscriptions.add atom.workspace.observeTextEditors @handleEditors
+    @subscriptions.add @errors.onChange @handleErrors
 
   clearMarkers: (editor, problems) =>
     markers = editor.findMarkers

        problem = m.getProperties().problem
        _.any(problems, (p) => _.isEqual(p, problem))
      ).value()
    _.invoke ms, 'destroy'

  decorateEditor: (editor, problems) =>
    # @clearMarkers(editor, problems)
    for problem in problems
      location = problem.location


    return unless problems?.length > 0
    @decorateEditor(editor, problems)

  dispose: =>
    @subscriptions.dispose()


module.exports = AnalysisDecorator
