I'm struggling to understand how to format and use objects and keep things efficient.
I come from an embedded C background.
In my node red home automation implementation I have a global array of objects, one per 'thing'. The things may be anything from a lightswitch to a heating zone to a weather object. There are currently around 100 'things' and eventually it will have maybe 200-300.
I work on a thing from the array by using
let myThing = global.get("thingsStatus["+ thingId + "]").
and then individual properties eg.
I have a common object format for most simple things and it has maybe 20 variables. Some things - such as heating or weather are much more complex and may add a further 10-15 variables.
I have done this by creating an optional 'extraobject' for the complex things. The extraobject takes a different form according to the type - weather/heating etc.
let windSpeed = myThing.extraobject.windSpeed
This all works but is prone to error when developing when I forget the property is part of the extra.I think I have made a rod for my back!
Q1.Would it be any less efficient to put all the properties for every thing type as the first level in the ting object?
This would mean that every item in the array had possibly dozens of properties that are meaningless.
Eg a lightswitch would have a windspeed property.
Q2. Is there a better way of having an array of objects where there are several different structures for the different object types?