Parameter lost during dispatch


I have a panel that contains a function I am trying to trigger, however when the command gets dispatched the settings object does not get passed along. I have some commands that are following this same pattern but none are going from view to package. Thoughts?

This is in my package main.

  activate: (state) ->
    @panelView = new PanelView
    atom.commands.add 'atom-workspace', "canvas:changeSettings": =>  @panelView.changeSettings()

These are in my view

$('.resolutionChange, .zoomChange').off('change').on 'change', ->
    settings = {"test":"val"}
    atom.commands.dispatch(atom.views.getView(atom.workspace.getActivePane()), "canvas:changeSettings", settings)

When this gets called the settings object is undefined

changeSettings: (settings) ->


Atom commands don’t have parameters. Atom commands are meant to be called by things like menu items or key bindings where parameters don’t make sense. (Yes, I realize that in Emacs and vim keybound commands can and do have parameters, but that’s not the way that Atom works.)

If you’ve got the view, you could call a function on it directly and pass the parameters that way.


Actually they do, but the parameter is not listed in the documentation.

activate: (state) ->
    @subscriptions = new CompositeDisposable

    @subscriptions.add atom.commands.add 'atom-workspace', 'hello:world': ({detail}) => @log(detail)
    @subscriptions.add atom.commands.add 'atom-workspace', 'hello:dispatch': -> atom.commands.dispatch(atom.views.getView(atom.workspace), 'hello:world', 'Hello World')

  deactivate: ->

  log: (message) ->
    console.log message

I would not recommend using commands that way though (at least in your case). Also keep in mind that, if you stick to this way, your command will also be visible in the command palette, in which case detail is null.
I have not seen your code but you could probably just call the function directly or, if you really want to use events inside your package, you should probably use a Emitter.


I am not sure what the ({detail}) syntax does but I removed the {} and I was able to get it going. Thank you so much.