Skip to content

Commit

Permalink
Add Pilot parsing, and load Pilots from sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Dec 11, 2016
1 parent 4ca88bd commit 04a6785
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/reducers/entitiesReducer.js
Original file line number Diff line number Diff line change
@@ -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,
});
110 changes: 110 additions & 0 deletions src/data/sampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
};


Expand Down
9 changes: 9 additions & 0 deletions src/features/pilots/Pilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.