Is it appropriate to use the CommandRegistry for native DOM events like mousedown?


I’ve just tried and it seems to work fine, but I don’t see it being used this way in other packages.

For instance in it uses jquery to register native events and then atom commands only to register higher level ones.

For my package it “seems” like it would be simpler just use the CommandRegistry for everything. And it seems to work… but I’m wondering if there’s a good reason why I shouldn’t.



This used to be the idiomatic way but Atom is trying to get rid of jQuery so that is out the window. I’m not sure what the replacement idiom should be but your way sounds fine to me.


@nathansobo should probably weigh in on this. I believe I read something where he said that jQuery event support would be going away eventually. I can’t find the reference for it right now though.


That is probably not true now that they have decided to support space-pen and jQuery.


I wouldn’t recommend using the command registry to listen for native events. It’s designed for commands that you intend to show up in the command palette. That doesn’t really make sense for things like “click”.

Also, the command registry uses the useCapture option of addEventListener to register event handlers. This means that handlers registered via the command registry will always be executed before handlers registered directly via DOM APIs. For commands this is fine, because everyone should be using the command registry to listen for commands anyway. Using the command registry for other kinds of events could lead to surprise when listeners registered via the command handler don’t interleave with native handlers during event bubbling.

I worked on a solution to this problem but it involved pretty severe intervention in the browser’s native event cascade mechanism, and it didn’t seem like a good use of time. Someday, we may be able to offer an mechanism that works consistently for both commands and events. Maybe. But for now I think we should stick to native handling mechanisms for standard events. I’d honestly consider enforcing this with an explicit black list once jQuery is gone.

Request: EventRegistery, a CommandRegistery equivalent for native events

@nathansobo Thanks for looking into this.


You’ll still need to register commands via the command registry.