mapseed/platform

Helper function for parsing the config object

Closed this issue · 0 comments

There are many places in the code where we need to examine the contents of the config object (i.e. the javascript object that's produced from a flavor's config.yml file) to look up a property. In many cases, these lookups involve scanning through an array of objects looking for an object with a particular property value. Typically we use underscore's _.find() or _.filter() methods to do this. The code is littered with _.finds and _.filterss, some of them doing redundant work, and all of them awkward looking and difficult to read at a glance. Furthermore, when property lookups fail, we sometimes return an empty object and sometimes do not. This inconsistency is a regular source of crashes stemming from mistakes in config.yml files.

I think it would be better to abstract all this config processing away into a helper function. Ideally we'd just pass this helper function the section of the config we'd like to scan and the target property, and the helper function would figure out what it needs to do to locate the property. We would consistently return an empty object if no target object is found.