Skip to content

Commit

Permalink
Update data loading reducer to parse nested unit definition
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jan 2, 2018
1 parent 58b9115 commit c8cabf2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/app/reducers/entitiesReducer.js
Expand Up @@ -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;
Expand Down

0 comments on commit c8cabf2

Please sign in to comment.