Idiomatic Redux store updates

@tlvince

2017-08-18

Rationale

Update store slice

Computed properties

ES2015 computed property names

AKA dynamic object keys

Object destructuring

ES2015 object destructuring

Assigns new variables from object properties

Object rest/spread

Object spread

Shallow-clones objects via:

Not yet formalised in ES spec!

Recap

Why?

  • shipments indexed by ID in shipments slice
    • see: normalising state shape
  • shipment has just been modified
    • e.g. api.saveChanges to update batch quantities
  • Need to update store slice immutably

Result

state was updated immutably with the parent shipment key omitted

Check with Babel REPL

Actual update

Fin!

References