From ae4f92cc5253ea3b79ea9193fcd51048e7aa3779 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 9 Sep 2014 14:45:31 -0700 Subject: [PATCH] Add onDidChangeStatuses --- spec/git-spec.coffee | 2 +- src/git.coffee | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/git-spec.coffee b/spec/git-spec.coffee index 4e3bb7de3..2cc0a6239 100644 --- a/spec/git-spec.coffee +++ b/spec/git-spec.coffee @@ -208,7 +208,7 @@ describe "Git", -> it "returns status information for all new and modified files", -> fs.writeFileSync(modifiedPath, 'making this path modified') statusHandler = jasmine.createSpy('statusHandler') - repo.on 'statuses-changed', statusHandler + repo.onDidChangeStatuses statusHandler repo.refreshStatus() waitsFor -> diff --git a/src/git.coffee b/src/git.coffee index bfabcf829..34beb474e 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -106,10 +106,21 @@ class Git onDidChangeStatus: (callback) -> @emitter.on 'did-change-status', callback + # Essential: Invoke the given callback when a multiple files' statuses have + # changed. For example, on window focus, the status of all the paths in the + # repo is checked. If any of them have changed, this will be fired. Call + # {::getPathStatus(path)} to get the status for your path of choice. + # + # * `callback` {Function} + onDidChangeStatuses: (callback) -> + @emitter.on 'did-change-statuses', callback + on: (eventName) -> switch eventName when 'status-changed' deprecate 'Use Git::onDidChangeStatus instead' + when 'statuses-changed' + deprecate 'Use Git::onDidChangeStatuses instead' else deprecate 'Git::on is deprecated. Use event subscription methods instead.' EmitterMixin::on.apply(this, arguments) @@ -423,4 +434,6 @@ class Git for submodulePath, submoduleRepo of @getRepo().submodules submoduleRepo.upstream = submodules[submodulePath]?.upstream ? {ahead: 0, behind: 0} - @emit 'statuses-changed' unless statusesUnchanged + unless statusesUnchanged + @emit 'statuses-changed' + @emitter.emit 'did-change-statuses'