Explore new 'shelter' data structure
The current ways of accessing shelter values are very fragile. Possibility for more robust data structure:
client.current = {
shelter: 'homeless',
renter: {
rent: 1530,
rentShare: 0,
contractRent: 0,
mortgage: 0,
housingInsurance: 0,
propertyTax: 0,
climateControl: true,
nonHeatElectricity: false,
phone: true,
fuelAssistance: false
},
homeless: {
// same
},
homeowner: {
// same
},
hasHousing: {
// same
}
}
Using the new data structure:
let timed = client[ timeframe ],
shelterVals = timed [ timed.shelter ],
mortgage = shelter.mortgage,
insurance = shelter.housingInsurance,
tax = shelter.propertyTax,
houseExpenes = mortgage + insurance + tax;
How it would work with inputs: When a user selects 'renter' only the rent properties would be changed. If they select 'homeowner', only the homeowner properties would be changed. Etc.
The point? Right now calculation functions have to check which type of shelter is in play and then get the correct values for that shelter. With this change, they don't need to do any of that, and they'll still be able to do the old checks if they need to (for example, they can check if the client is homeless).
Now that we have the ability to set and access nested values, this could be our best, and a great, option.
This may be a lower priority. If we find we're having trouble with bugs involving shelter in calculation functions, we'll raise the priority.
There is one problem with the idea - the utilities part of the shelter object will look like it's reset each time without some fancy code work, since renter, housing subsidy, and homeowner will all have their own values for it. Something to think about.
See the changeClient() in '/src/containers/VisitPage.js'.