API: Observe key binding changes?


My package Jumpy has a piece of code:

    initKeyFilters: ->
    @filteredJumpyKeys = @getFilteredJumpyKeys()
    Object.observe atom.keymaps.keyBindings, ->
        @filteredJumpyKeys = @getFilteredJumpyKeys()

Object.observe is deprecated and already removed in Stable Chrome.

I could use a polyfill, but I’d rather not. I could use Proxy, I am pretty sure. Haven’t played with that yet. I’d also rather not. I’d rather have it provided by the API.

NOTE: This was always a little shady, as I stumbled on that keyBindings object. It’s not really returned back from the api.

I’m sure there’s a better way to do it. At least these days. If so, I would probably hit the two birds with one stone. Object observe and not using the keyBindings object.


(Hopefully this isn’t too obvious, but I couldn’t find it in the API docs, and of course couldn’t find it the first time around either…although I was very gung ho Object.observe, as I don’t think the cool kids had decreed it uncool yet)


You are correct, there isn’t a method for doing this in the Atom API. There are some other undocumented APIs in the KeymapManager, but none of them do quite what you’re looking for either. (And they’re undocumented … so they could change at any time and without notice.)