ariesshrimp / weather-app

Code challenge
0 stars 0 forks source link

Fix setState of ForecastDisplay #13

Open ariesshrimp opened 8 years ago

ariesshrimp commented 8 years ago

Currently <ForecastDisplay> uses Object.assign in its componentDidMount updates. Unfortunately, Object.assign keeps falsy and undefined values from its incoming objects. That means that sensible backups are still needed internally in the render method to avoid showing "undefined" values.

ariesshrimp commented 8 years ago

This is resolved. Added a default object catch into the Object.assign list to override any unwanted undefineds with the right default attributes.

ariesshrimp commented 8 years ago

This is worse than I thought. Object.assign doesn't deep check nested data structures. For example:

const original = {
  prop1: {
    prop2: true
  }
}

const new = {
  prop1: {
    prop3: 'OIJOJSDOFJOIJF'
  }
}

const updated = Object.assign({}, original, new)
updated.prop1.prop2 // undefined, because new.prop1 doesn't have one.