Design pattern : Separated JSON files for menus and keymaps


#1

I’m just trying to understand the reason behind having separated folders for Keymaps and Menus, especially that we can have a menu and keymap entries in the package.json ? Isn’t a good idea to have only one manifest file or it’s much better to separate the configuration?


#2

For packages that have lots of menus, keymaps, snippets, or stylesheets it is convenient to have multiple files with subsets of those configurations. For example, maybe I have a package that offers the same set of testing snippets for various languages. I could have one file for Ruby, one for Python, one for JavaScript, etc. Keeping them all together in the snippets directory makes sense and then we don’t have to come up with some file extension to signify what kind of configuration file it is :grinning:

It’s an arbitrary choice, but one that makes sense, I think.


#3

Speaking as a newbie to Atom, the parts that made immediate sense to me (and thus didn’t require any energy to figure out) were those niche folders. I can open up any package, look at its keymap directory, and immediately understand what it’s trying to do. If the keybindings are defined in the code files, or in package.json, then you have no initial idea where they are and you have to do a lot of searching. For someone who doesn’t have experience reading JavaScript, keybindings buried in some interface.js file amid a dozen vaguely-named JS files would be the opposite of useful.


#4

Agreed. It’s also self-documenting: no matter what an author names a file, any casual reader will get the gist of its purpose if it’s in a subdirectory named keymaps.