Permalink
Browse files

Add Pilot parsing, and load Pilots from sample data

  • Loading branch information...
markerikson committed Dec 7, 2016
1 parent 4ca88bd commit 04a67852f08ac5e62262a7dc552d1d821543d1bb
Showing with 138 additions and 1 deletion.
  1. +19 −1 src/app/reducers/entitiesReducer.js
  2. +110 −0 src/data/sampleData.js
  3. +9 −0 src/features/pilots/Pilot.js
@@ -1,8 +1,26 @@
import {createReducer} from "common/utils/reducerUtils";
import {DATA_LOADED} from "features/tools/toolConstants";
import schema from "app/schema"
const initialState = schema.getDefaultState();
export function loadData(state, payload) {
// Create a Redux-ORM session from our entities "tables"
const session = schema.from(state);
// Get a reference to the correct version of the Pilots class for this Session
const {Pilot} = session;
const {pilots} = payload;
// Queue up creation commands for each pilot entry
pilots.forEach(pilot => Pilot.parse(pilot));
// Apply the queued updates and return the updated "tables"
return session.reduce();
}
export default createReducer(initialState, {
});
[DATA_LOADED] : loadData,
});
View
@@ -3,6 +3,116 @@ const sampleData = {
name : "Black Widow Company",
affiliation : "wd",
},
pilots : [
{
id : 1,
name : "Natasha Kerensky",
rank : "Captain",
gunnery : 2,
piloting : 2,
age : 52,
mechType : "WHM-6R",
},
{
id : 2,
name : "Colin Maclaren",
rank : "Sergeant",
gunnery : 3,
piloting : 4,
age : 43,
mechType : "MAD-3R",
},
{
id : 3,
name : "Lynn Sheridan",
rank : "Corporal",
gunnery : 4,
piloting : 5,
age : 27,
mechType : "CRD-3R",
},
{
id : 4,
name : "John Hayes",
rank : "Sergeant",
gunnery : 3,
piloting : 4,
age : 34,
mechType : "GRF-1N",
},
{
id : 5,
name : "Takiro Ikeda",
rank : "Lieutenant",
gunnery : 3,
piloting : 4,
age : 41,
mechType : "ARC-2R",
},
{
id : 6,
name : "Miklos Delius",
rank : "Corporal",
gunnery : 4,
piloting : 4,
age : 31,
mechType : "ARC-2R",
},
{
id : 7,
name : "Nikolai Koniev",
rank : "Private",
gunnery : 3,
piloting : 4,
age : 39,
mechType : "WSP-1A",
},
{
id : 8,
name : "Alex Ward",
rank : "Corporal",
gunnery : 4,
piloting : 5,
age : 36,
mechType : "WSP-1A",
},
{
id : 9,
name : "John Clavell",
rank : "Lieutenant",
gunnery : 3,
piloting : 4,
age : 40,
mechType : "RFL-3N",
},
{
id : 10,
name : "Piet Nichols",
rank : "Corporal",
gunnery : 4,
piloting : 5,
age : 37,
mechType : "PXH-1K",
},
{
id : 11,
name : "Simon Fraser",
rank : "Sergeant",
gunnery : 3,
piloting : 4,
age : 32,
mechType : "STG-3R",
},
{
id : 12,
name : "Mohammar Jahan",
rank : "Corporal",
gunnery : 3,
piloting : 5,
age : 29,
mechType : "STG-3R",
},
]
};
@@ -3,6 +3,15 @@ import {Model} from "redux-orm";
export default class Pilot extends Model {
static parse(pilotData) {
// We could do useful stuff in here with relations,
// but since we have no relations yet, all we need
// to do is pass the pilot data on to create()
// Note that in a static class method, `this` is the
// class itself, not an instance
return this.create(pilotData);
}
}
Pilot.modelName = "Pilot";

0 comments on commit 04a6785

Please sign in to comment.