Can you call activationCommands from a DOM element?


I’m a newbie and this is probably a stupid question, but, whatever, here it is.
For the wordcount tutorial, if you added a button element to the message, could you call the wordcount:toggle action from the view?

my code is below

btn = document.createElement('button');
btn.type = 'button';
btn.onclick = function(){wordcount:toggle()};
btnlabel = document.createTextNode('CLICK ME');

const message = document.createElement('div');
message.textContent = 'The wordcount package is Alive! It\'s ALIVE!';


No, this isn’t possible because the string wordcount:toggle only means something to the CommandRegistry. It isn’t something that exists as a symbol in the JavaScript interpreter itself. However, if the wordcount:toggle command calls a specific function that you have a reference to, you could call that function instead.


atom.commands.dispatch() does what is being asked for, and that’s how atom-toolbar functions.