Having `activationEvents` is confusing


If I have the following

"activationEvents": [

Then atom.packages.once('activated',eventHandler's event handler is no longer called. Is this expected.

Configuration vars don't show up

In fact even activate is not called Untill the event is triggered


Turns out I don’t need "activationEvents": [ ],

This tutorial seems a bit confusing : https://atom.io/docs/latest/your-first-package Moving on for now.


If you search for activationEvents on the board here, you’ll find all sorts of posts that talk about what it is useful for. Like this one:


But you should use it whenever possible. When you don’t have it your activate function is called during the initial Atom load time which slows it down. Atom’s load time is a big problem so you should be a good citizen and not activate at load.


Having re-read https://atom.io/docs/latest/your-first-package its fairly clear what the purpose of activationEvents is. So my bad.

Is there a way to say only activate me if the file extension is .ts?


Unfortunately no. I’ve wanted to do the same thing. Just be sure to do as little as possible in your activate routine. Ideally just set up one event handler.


You can see an example of what @mark_hahn is talking about in my tabs-to-spaces package:


The full code of the package doesn’t get loaded until something happens that requires it, just like activationEvents … but giving me more freedom in when it activates. Like onSave:



You can even put off your require statements. It is a little bit of a pain to have to use something like @package everywhere but it helps. This isn’t needed on built-ins like fs or in common ones like underscore.


I saw in someone’s package how to delay module requires and not have to use @module. Just define the module variable to null at the top and then initialize the module variable in the activate routine.

fs = null

module.exports =
  activate: ->
    fs = require 'fs'
  start: ->
    exists = fs.existsSync 'myFile'