Return subscription from RootView.eachEditor()

This commit is contained in:
Kevin Sawicki
2013-06-12 11:37:49 -07:00
parent 65b08e2914
commit 04c5e9fa42
2 changed files with 15 additions and 1 deletions

View File

@@ -327,6 +327,18 @@ describe "RootView", ->
expect(count).toBe 1
expect(callbackEditor).toBe rootView.getActiveView()
it "returns a subscription that can be disabled", ->
count = 0
callback = (editor) -> count++
subscription = rootView.eachEditor(callback)
expect(count).toBe 1
rootView.getActiveView().splitRight()
expect(count).toBe 2
subscription.off()
rootView.getActiveView().splitRight()
expect(count).toBe 2
describe ".eachBuffer(callback)", ->
beforeEach ->
rootView.attachToDom()

View File

@@ -205,7 +205,9 @@ class RootView extends View
# callback - A {Function} to call
eachEditor: (callback) ->
callback(editor) for editor in @getEditors()
@on 'editor:attached', (e, editor) -> callback(editor)
attachedCallback = (e, editor) -> callback(editor)
@on('editor:attached', attachedCallback)
off: => @off('editor:attached', attachedCallback)
# Fires a callback on each open {EditSession}.
#