diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 974321041..2940aa2e1 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -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() diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 851701fc1..ad6cd6661 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -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}. #