mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Return subscription from RootView.eachEditor()
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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}.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user