mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Add Pane::observeItems
This commit is contained in:
@@ -292,6 +292,19 @@ describe "Pane", ->
|
||||
expect(item3.isDestroyed()).toBe true
|
||||
expect(pane.getItems()).toEqual []
|
||||
|
||||
describe "::observeItems()", ->
|
||||
it "invokes the observer with all current and future items", ->
|
||||
pane = new Pane(items: [new Item, new Item])
|
||||
[item1, item2] = pane.getItems()
|
||||
|
||||
observed = []
|
||||
pane.observeItems (item) -> observed.push(item)
|
||||
|
||||
item3 = new Item
|
||||
pane.addItem(item3)
|
||||
|
||||
expect(observed).toEqual [item1, item2, item3]
|
||||
|
||||
describe "when an item emits a destroyed event", ->
|
||||
it "removes it from the list of items", ->
|
||||
pane = new Pane(items: [new Item("A"), new Item("B"), new Item("C")])
|
||||
|
||||
@@ -134,6 +134,15 @@ class Pane extends Model
|
||||
onDidMoveItem: (callback) ->
|
||||
@emitter.on 'did-move-item', callback
|
||||
|
||||
# Public: Invoke the given callback with all current and future items.
|
||||
#
|
||||
# * `callback` {Function} to be called with current and future items.
|
||||
#
|
||||
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
||||
observeItems: (callback) ->
|
||||
callback(item) for item in @getItems()
|
||||
@onDidAddItem ({item}) -> callback(item)
|
||||
|
||||
# Public: Invoke the given callback when the value of {::getActiveItem}
|
||||
# changes.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user