mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Retrigger event after package module is activated
The event that triggers the package module to be activated is now retriggered after the package module is initialized but without any previously registered handlers. Instead only the handlers registered by the package module will be triggered. The prior event handlers are then restored after the event is retriggered. This allows package modules to bind event handlers during initialization that will be triggered by the same event that caused the package module intialization to occur. This simplifies the common case of having the same event cause a package module to initialize and attach.
This commit is contained in:
committed by
Corey Johnson & Kevin Sawicki
parent
51f5bb95d0
commit
641a0d43cc
36
spec/app/atom-package-spec.coffee
Normal file
36
spec/app/atom-package-spec.coffee
Normal file
@@ -0,0 +1,36 @@
|
||||
RootView = require 'root-view'
|
||||
AtomPackage = require 'atom-package'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "AtomPackage", ->
|
||||
describe ".load()", ->
|
||||
[packageMainModule, pack, rootView] = []
|
||||
beforeEach ->
|
||||
rootView = new RootView(fixturesProject.getPath())
|
||||
pack = new AtomPackage(fs.resolve(config.packageDirPaths..., 'package-with-activation-events'))
|
||||
packageMainModule = require 'fixtures/packages/package-with-activation-events/main'
|
||||
spyOn(packageMainModule, 'activate').andCallThrough()
|
||||
pack.load()
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
|
||||
describe "when the package metadata includes activation events", ->
|
||||
it "defers activating the package until an activation event bubbles to the root view", ->
|
||||
expect(packageMainModule.activate).not.toHaveBeenCalled()
|
||||
rootView.trigger 'activation-event'
|
||||
expect(packageMainModule.activate).toHaveBeenCalled()
|
||||
|
||||
it "triggers the activation event on all handlers registered during activation", ->
|
||||
rootView.open('sample.js')
|
||||
editor = rootView.getActiveEditor()
|
||||
eventHandler = jasmine.createSpy("activation-event")
|
||||
editor.command 'activation-event', eventHandler
|
||||
editor.trigger 'activation-event'
|
||||
expect(packageMainModule.activate.callCount).toBe 1
|
||||
expect(packageMainModule.activationEventCallCount).toBe 1
|
||||
expect(eventHandler.callCount).toBe 1
|
||||
editor.trigger 'activation-event'
|
||||
expect(packageMainModule.activationEventCallCount).toBe 2
|
||||
expect(eventHandler.callCount).toBe 2
|
||||
expect(packageMainModule.activate.callCount).toBe 1
|
||||
Reference in New Issue
Block a user