farmOS / field-kit

A modular, offline-first companion app to farmOS.
https://farmOS.org
GNU General Public License v3.0
60 stars 39 forks source link

Replace global object w/ mountFieldModule method. #382

Closed jgaehring closed 4 years ago

jgaehring commented 4 years ago

A great thing about writing documentation is it makes you look at your API from the inside out, and you see things in a new light.

I realized writing the documentation for 0.6.0 that it was kinda funky the way we were requiring the Field Module be mounted with an assignment to the global namespace:

window.farmOS.modules[modConfig.name] = modConfig;

It reveals a few more implementation details than I'd like, plus we don't really have any other reason to expose the module config globally like that (it get's pulled into Vuex separately), and it's just plain ugly.

So I know this is a breaking change, but I just wanted to provide a function instead; so now it's,

window.farmOS.mountFieldModule(module);

which seems much cleaner. It will allow for more a more flexible implementation, because that mountFieldModule method can be whatever we want, essentially. I also stopped referring to it as the module.config.js, which seems less accurate than just referring to the main object that gets mounted as the module itself.

This PR also includes the initial commit of API.md, as outline in #380, with the mountFieldModule change included.

jgaehring commented 4 years ago

Also note that I'm holding off from merging this into develop primarily because this represents a breaking change to the API and I want to discuss with @mstenta how to automate updates to the corresponding modules it affects. I've already updated the Spray and Precip modules, but we need some way to get those updates to https://test.farmos.net, or else we'll end up breaking https://develop.farmos.app when we merge.