Having `activationEvents` is confusing


#1

If I have the following

"activationEvents": [
        "typescript:format-code"
    ],

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


Configuration vars don't show up
#2

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


#3

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.


#4

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:


#5

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.


#6

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?


#7

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.


#8

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

https://github.com/lee-dohm/tabs-to-spaces/blob/master/lib/index.coffee#L11-L23

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:

https://github.com/lee-dohm/tabs-to-spaces/blob/master/lib/index.coffee#L29-L42


#9

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.


#10

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()
  start: ->
    exists = fs.existsSync 'myFile'