File tree Expand file tree Collapse file tree 3 files changed +138
-1
lines changed Expand file tree Collapse file tree 3 files changed +138
-1
lines changed Original file line number Diff line number Diff line change 11import { createReducer } from "common/utils/reducerUtils" ;
22
3+ import { DATA_LOADED } from "features/tools/toolConstants" ;
4+
35import schema from "app/schema"
46
57const initialState = schema . getDefaultState ( ) ;
68
9+ export function loadData ( state , payload ) {
10+ // Create a Redux-ORM session from our entities "tables"
11+ const session = schema . from ( state ) ;
12+ // Get a reference to the correct version of the Pilots class for this Session
13+ const { Pilot} = session ;
14+
15+ const { pilots} = payload ;
16+ // Queue up creation commands for each pilot entry
17+ pilots . forEach ( pilot => Pilot . parse ( pilot ) ) ;
18+
19+ // Apply the queued updates and return the updated "tables"
20+ return session . reduce ( ) ;
21+ }
22+
23+
724export default createReducer ( initialState , {
8- } ) ;
25+ [ DATA_LOADED ] : loadData ,
26+ } ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,116 @@ const sampleData = {
33 name : "Black Widow Company" ,
44 affiliation : "wd" ,
55 } ,
6+ pilots : [
7+ {
8+ id : 1 ,
9+ name : "Natasha Kerensky" ,
10+ rank : "Captain" ,
11+ gunnery : 2 ,
12+ piloting : 2 ,
13+ age : 52 ,
14+ mechType : "WHM-6R" ,
15+ } ,
16+ {
17+ id : 2 ,
18+ name : "Colin Maclaren" ,
19+ rank : "Sergeant" ,
20+ gunnery : 3 ,
21+ piloting : 4 ,
22+ age : 43 ,
23+ mechType : "MAD-3R" ,
24+ } ,
25+ {
26+ id : 3 ,
27+ name : "Lynn Sheridan" ,
28+ rank : "Corporal" ,
29+ gunnery : 4 ,
30+ piloting : 5 ,
31+ age : 27 ,
32+ mechType : "CRD-3R" ,
33+ } ,
34+ {
35+ id : 4 ,
36+ name : "John Hayes" ,
37+ rank : "Sergeant" ,
38+ gunnery : 3 ,
39+ piloting : 4 ,
40+ age : 34 ,
41+ mechType : "GRF-1N" ,
42+ } ,
43+ {
44+ id : 5 ,
45+ name : "Takiro Ikeda" ,
46+ rank : "Lieutenant" ,
47+ gunnery : 3 ,
48+ piloting : 4 ,
49+ age : 41 ,
50+ mechType : "ARC-2R" ,
51+ } ,
52+ {
53+ id : 6 ,
54+ name : "Miklos Delius" ,
55+ rank : "Corporal" ,
56+ gunnery : 4 ,
57+ piloting : 4 ,
58+ age : 31 ,
59+ mechType : "ARC-2R" ,
60+ } ,
61+ {
62+ id : 7 ,
63+ name : "Nikolai Koniev" ,
64+ rank : "Private" ,
65+ gunnery : 3 ,
66+ piloting : 4 ,
67+ age : 39 ,
68+ mechType : "WSP-1A" ,
69+ } ,
70+ {
71+ id : 8 ,
72+ name : "Alex Ward" ,
73+ rank : "Corporal" ,
74+ gunnery : 4 ,
75+ piloting : 5 ,
76+ age : 36 ,
77+ mechType : "WSP-1A" ,
78+ } ,
79+ {
80+ id : 9 ,
81+ name : "John Clavell" ,
82+ rank : "Lieutenant" ,
83+ gunnery : 3 ,
84+ piloting : 4 ,
85+ age : 40 ,
86+ mechType : "RFL-3N" ,
87+ } ,
88+ {
89+ id : 10 ,
90+ name : "Piet Nichols" ,
91+ rank : "Corporal" ,
92+ gunnery : 4 ,
93+ piloting : 5 ,
94+ age : 37 ,
95+ mechType : "PXH-1K" ,
96+ } ,
97+ {
98+ id : 11 ,
99+ name : "Simon Fraser" ,
100+ rank : "Sergeant" ,
101+ gunnery : 3 ,
102+ piloting : 4 ,
103+ age : 32 ,
104+ mechType : "STG-3R" ,
105+ } ,
106+ {
107+ id : 12 ,
108+ name : "Mohammar Jahan" ,
109+ rank : "Corporal" ,
110+ gunnery : 3 ,
111+ piloting : 5 ,
112+ age : 29 ,
113+ mechType : "STG-3R" ,
114+ } ,
115+ ]
6116} ;
7117
8118
Original file line number Diff line number Diff line change @@ -3,6 +3,15 @@ import {Model} from "redux-orm";
33
44export default class Pilot extends Model {
55
6+ static parse ( pilotData ) {
7+ // We could do useful stuff in here with relations,
8+ // but since we have no relations yet, all we need
9+ // to do is pass the pilot data on to create()
10+
11+ // Note that in a static class method, `this` is the
12+ // class itself, not an instance
13+ return this . create ( pilotData ) ;
14+ }
615}
716
817Pilot . modelName = "Pilot" ;
You can’t perform that action at this time.
0 commit comments