Multiple activationCommands get all called


Pretty new to Atom here.
I am developing a package available from the tree-view context menu with several submenus. I would like to link each voice in the menu to a command. Let’s say I have

Menu 1 > Submenu 1 > [ Item 1, Item 2 ]

Item 1 and item 2 should both toggle the package, but they should be linked to different methods. My fist attempt is to create the menu like this:

{ 'label': 'Item 1', 'command': 'my-package:doThingOne' }
{ 'label': 'Item 2', 'command': 'my-package:doThingTwo' }

Then in the package.json file add the activation commands:

"activationCommands": { 
  "atom-workspace": [

Finally, in the package code (I’m just using the view), I initialise the package so that:

initialize: (serializeState) ->
  atom.commands.add 'atom-workspace',
    'my-package:doThingOne': @doThing 'one'
    'my-package:doThingTwo': @doThing 'two'

Unfortunately, when I trigger the package, both commands are executed, and the package fails to start.
Could you point me out what is the issue here? And maybe, do you think this could be the best approach to do it?


As note, the methods get called in reverse order, so doThing 'two' gets called before doThing 'one'.

initialize: (serializeState) ->
  atom.commands.add 'atom-workspace',
    'my-package:doThingOne': @doThing 'one' # < HERE
    'my-package:doThingTwo': @doThing 'two' # < AND HERE

I think this is the source your problem, instead of registering a function that will call @doThing, you’re actually calling it instead (except if doThing is a curried method, but given the behavior you observe I doubt it’s the case).

It should rather look like this:

initialize: (serializeState) ->
  atom.commands.add 'atom-workspace',
    'my-package:doThingOne': => @doThing 'one' 
    'my-package:doThingTwo': => @doThing 'two' 


Ok, this definitely solved my problem, thank you very much!