Permalink
Browse files

Update data loading reducer to parse nested unit definition

  • Loading branch information...
markerikson committed Dec 30, 2017
1 parent 58b9115 commit c8cabf2bdc9c3a255e4f4081b177cf3fe84bf768
Showing with 4 additions and 5 deletions.
  1. +4 −5 src/app/reducers/entitiesReducer.js
@@ -10,21 +10,20 @@ export function loadData(state, payload) {
// Create a Redux-ORM session from our entities "tables"
const session = orm.session(state);
// Get a reference to the correct version of model classes for this Session
const {Pilot, MechDesign, Mech} = session;
const {Unit, Pilot, Mech, MechDesign} = session;
const {pilots, designs, mechs} = payload;
const {unit, designs} = payload;
// Clear out any existing models from state so that we can avoid
// conflicts from the new data coming in if data is reloaded
[Pilot, Mech, MechDesign].forEach(modelType => {
[Unit, Pilot, Mech, MechDesign].forEach(modelType => {
modelType.all().toModelArray().forEach(model => model.delete());
});
// Immutably update the session state as we insert items
pilots.forEach(pilot => Pilot.parse(pilot));
Unit.parse(unit);
designs.forEach(design => MechDesign.parse(design));
mechs.forEach(mech => Mech.parse(mech));
// Return the new "tables" object containing the updates
return session.state;

0 comments on commit c8cabf2

Please sign in to comment.