diff --git a/spec/package-spec.coffee b/spec/package-spec.coffee index bbb00ca81..b94f86a0f 100644 --- a/spec/package-spec.coffee +++ b/spec/package-spec.coffee @@ -102,6 +102,6 @@ describe "Package", -> theme.activate() it "deactivated event fires on .deactivate()", -> - theme.on 'deactivated', spy = jasmine.createSpy() + theme.onDidDeactivate spy = jasmine.createSpy() theme.deactivate() expect(spy).toHaveBeenCalled() diff --git a/src/package.coffee b/src/package.coffee index 707e7b591..7a8133466 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -4,8 +4,10 @@ _ = require 'underscore-plus' async = require 'async' CSON = require 'season' fs = require 'fs-plus' -{Emitter} = require 'emissary' +EmitterMixin = require('emissary').Emitter +{Emitter} = require 'event-kit' Q = require 'q' +{deprecate} = require 'grim' $ = null # Defer require in case this is in the window-less browser process ScopedProperties = require './scoped-properties' @@ -14,7 +16,7 @@ ScopedProperties = require './scoped-properties' # stylesheets, keymaps, grammar, editor properties, and menus. module.exports = class Package - Emitter.includeInto(this) + EmitterMixin.includeInto(this) @stylesheetsDir: 'stylesheets' @@ -38,10 +40,33 @@ class Package mainModule: null constructor: (@path, @metadata) -> + @emitter = new Emitter @metadata ?= Package.loadMetadata(@path) @name = @metadata?.name ? path.basename(@path) @reset() + ### + Section: Events + ### + + # Essential: Invoke the given callback when all packages have been activated. + # + # * `callback` {Function} + onDidDeactivate: (callback) -> + @emitter.on 'did-deactivate', callback + + on: (eventName) -> + switch eventName + when 'deactivated' + deprecate 'Use Package::onDidDeactivate instead' + else + deprecate 'Package::on is deprecated. Use event subscription methods instead.' + EmitterMixin::on.apply(this, arguments) + + ### + Section: Methods + ### + enable: -> atom.config.removeAtKeyPath('core.disabledPackages', @name) @@ -243,7 +268,8 @@ class Package @deactivateResources() @deactivateConfig() @mainModule?.deactivate?() if @mainActivated - @emit('deactivated') + @emit 'deactivated' + @emitter.emit 'did-deactivate' deactivateConfig: -> @mainModule?.deactivateConfig?()