Permalink
Browse files

Add a Unit model class

  • Loading branch information...
markerikson committed Dec 30, 2017
1 parent 361a1aa commit 87a5f9e6826df2bd12ce83a1d0a1ff831860b47c
Showing with 31 additions and 1 deletion.
  1. +3 −1 src/app/schema/schema.js
  2. +28 −0 src/features/unitInfo/Unit.js
View
@@ -3,8 +3,10 @@ import {ORM } from "redux-orm";
import Pilot from "features/pilots/Pilot";
import MechDesign from "features/mechs/MechDesign";
import Mech from "features/mechs/Mech";
import Unit from "features/unitInfo/Unit";
const orm = new ORM();
orm.register(Pilot, MechDesign, Mech);
orm.register(Pilot, MechDesign, Mech, Unit);
export default orm;
@@ -0,0 +1,28 @@
import {Model, many, attr} from "redux-orm";
export default class Unit extends Model {
static modelName = "Unit";
static fields = {
id : attr(),
name : attr(),
affiliation : attr(),
color : attr(),
pilots : many("Pilot"),
mechs : many("Mech")
};
static parse(unitData) {
const {Pilot, Mech} = this.session;
const parsedData = {
...unitData,
pilots : unitData.pilots.map(pilotEntry => Pilot.parse(pilotEntry)),
mechs : unitData.mechs.map(mechEntry => Mech.parse(mechEntry)),
};
return this.upsert(parsedData);
}
}

0 comments on commit 87a5f9e

Please sign in to comment.