From 04c5e9fa42b742cb4e0b4998d16cbc30a142d96a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 12 Jun 2013 11:37:49 -0700 Subject: [PATCH] Return subscription from RootView.eachEditor() --- spec/app/root-view-spec.coffee | 12 ++++++++++++ src/app/root-view.coffee | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) 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}. #