Add atom.project.observeBuffers

This makes `onDidAddBuffer` symmetrical with other `onDidAddX` methods and their `observeXs`. It also documents `onDidAddBuffer` and adds tests for it.

Released under CC0.
This commit is contained in:
Andres Suarez
2016-08-22 15:35:02 -07:00
parent 89c638a2c7
commit 4ca6eaff34
2 changed files with 66 additions and 0 deletions

View File

@@ -89,9 +89,27 @@ class Project extends Model
onDidChangePaths: (callback) ->
@emitter.on 'did-change-paths', callback
# Public: Invoke the given callback when a text buffer is added to the
# project.
#
# * `callback` {Function} to be called when a text buffer is added.
# * `buffer` A {TextBuffer} item.
#
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidAddBuffer: (callback) ->
@emitter.on 'did-add-buffer', callback
# Public: Invoke the given callback with all current and future text
# buffers in the project.
#
# * `callback` {Function} to be called with current and future text buffers.
# * `buffer` A {TextBuffer} item.
#
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
observeBuffers: (callback) ->
callback(buffer) for buffer in @getBuffers()
@onDidAddBuffer callback
###
Section: Accessing the git repository
###