Skip to content

Commit 92626ee

Browse files
committed
Put initial state in seperate file
1 parent 225c5f6 commit 92626ee

File tree

3 files changed

+78
-74
lines changed

3 files changed

+78
-74
lines changed

src/intefaces/Interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface ApplicationStateInt {
7272
selectableChildren: number[];
7373
ancestors: number[];
7474
initialApplicationFocusChild: ChildInt;
75-
focusChild: ChildInt;
75+
focusChild: object;
7676
components: ComponentsInt;
7777
appDir: string;
7878
editMode: number;

src/reducers/componentReducer.ts

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
ComponentInt,
3-
ChildInt,
4-
ApplicationStateInt,
5-
Action,
6-
} from '../intefaces/Interfaces';
1+
import { initialApplicationState } from './initialState';
2+
import { Action } from '../intefaces/Interfaces';
73

84
import {
95
LOAD_INIT_DATA,
@@ -33,7 +29,7 @@ import {
3329
UNDO,
3430
REDO,
3531
EDIT_MODE,
36-
EDIT_COMPONENT
32+
EDIT_COMPONENT,
3733
} from '../actionTypes/index';
3834

3935
import {
@@ -61,66 +57,9 @@ import {
6157
toggleEditMode,
6258
editComponent,
6359
undo,
64-
redo
60+
redo,
6561
} from '../utils/componentReducer.util';
66-
import cloneDeep from '../helperFunctions/cloneDeep';
67-
68-
const appComponent: ComponentInt = {
69-
id: 1,
70-
stateful: false,
71-
classBased: false,
72-
title: 'App',
73-
color: '#FF6D00',
74-
props: [],
75-
nextPropId: 1,
76-
position: {
77-
x: 25,
78-
y: 25,
79-
width: 600,
80-
height: 400,
81-
},
82-
childrenArray: [],
83-
nextChildId: 1,
84-
focusChildId: 0,
85-
};
8662

87-
const initialApplicationFocusChild: ChildInt = {
88-
childId: 0,
89-
componentName: null,
90-
position: {
91-
x: 25,
92-
y: 25,
93-
width: 800,
94-
height: 550,
95-
},
96-
childType: null,
97-
childSort: 0,
98-
childComponentId: 0,
99-
color: null,
100-
htmlElement: null,
101-
HTMLInfo: null,
102-
};
103-
104-
const initialApplicationState: ApplicationStateInt = {
105-
tutorial: 0,
106-
imageSource: '',
107-
totalComponents: 1,
108-
nextId: 2,
109-
successOpen: false,
110-
errorOpen: false,
111-
focusComponent: appComponent,
112-
selectableChildren: [],
113-
ancestors: [],
114-
initialApplicationFocusChild,
115-
focusChild: cloneDeep(initialApplicationFocusChild),
116-
editMode: -1,
117-
components: [appComponent],
118-
appDir: '',
119-
loading: false,
120-
history: [],
121-
historyIndex: 0,
122-
future: []
123-
};
12463

12564
const componentReducer = (state = initialApplicationState, action: Action) => {
12665
switch (action.type) {
@@ -141,8 +80,8 @@ const componentReducer = (state = initialApplicationState, action: Action) => {
14180
return deleteChild(state, action.payload);
14281
case DELETE_COMPONENT:
14382
return deleteComponent(state, action.payload);
144-
case EDIT_COMPONENT:
145-
return editComponent(state, action.payload);
83+
case EDIT_COMPONENT:
84+
return editComponent(state, action.payload);
14685
case TOGGLE_STATE:
14786
return toggleComponentState(state, action.payload);
14887
case TOGGLE_CLASS:
@@ -178,16 +117,16 @@ const componentReducer = (state = initialApplicationState, action: Action) => {
178117
return addProp(state, action.payload);
179118
case DELETE_PROP:
180119
return deleteProp(state, action.payload);
181-
case EDIT_MODE:
182-
return toggleEditMode(state, action.payload);
120+
case EDIT_MODE:
121+
return toggleEditMode(state, action.payload);
183122
case UPDATE_HTML_ATTR:
184123
return updateHtmlAttr(state, action.payload);
185124
case UPDATE_CHILDREN_SORT:
186125
return updateChildrenSort(state, action.payload);
187-
case UNDO:
188-
return undo(state);
189-
case REDO:
190-
return redo(state);
126+
case UNDO:
127+
return undo(state);
128+
case REDO:
129+
return redo(state);
191130
default:
192131
return state;
193132
}

src/reducers/initialState.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import cloneDeep from '../helperFunctions/cloneDeep';
2+
3+
import {
4+
ComponentInt,
5+
ChildInt,
6+
ApplicationStateInt,
7+
} from '../intefaces/Interfaces';
8+
9+
const appComponent: ComponentInt = {
10+
id: 1,
11+
stateful: false,
12+
classBased: false,
13+
title: 'App',
14+
color: '#FF6D00',
15+
props: [],
16+
nextPropId: 1,
17+
position: {
18+
x: 25,
19+
y: 25,
20+
width: 600,
21+
height: 400,
22+
},
23+
childrenArray: [],
24+
nextChildId: 1,
25+
focusChildId: 0,
26+
};
27+
28+
const initialApplicationFocusChild: ChildInt = {
29+
childId: 0,
30+
componentName: null,
31+
position: {
32+
x: 25,
33+
y: 25,
34+
width: 800,
35+
height: 550,
36+
},
37+
childType: null,
38+
childSort: 0,
39+
childComponentId: 0,
40+
color: null,
41+
htmlElement: null,
42+
HTMLInfo: null,
43+
};
44+
45+
export const initialApplicationState: ApplicationStateInt = {
46+
tutorial: 0,
47+
imageSource: '',
48+
totalComponents: 1,
49+
nextId: 2,
50+
successOpen: false,
51+
errorOpen: false,
52+
focusComponent: appComponent,
53+
selectableChildren: [],
54+
ancestors: [],
55+
initialApplicationFocusChild,
56+
focusChild: cloneDeep(initialApplicationFocusChild),
57+
editMode: -1,
58+
components: [appComponent],
59+
appDir: '',
60+
loading: false,
61+
history: [],
62+
historyIndex: 0,
63+
future: []
64+
};
65+

0 commit comments

Comments
 (0)