@@ -19,91 +19,80 @@ import {
19
19
CREATE_APPLICATION ,
20
20
CREATE_APPLICATION_SUCCESS ,
21
21
CREATE_APPLICATION_ERROR ,
22
- TOGGLE_DRAGGING ,
23
22
MOVE_TO_BOTTOM ,
24
23
MOVE_TO_TOP ,
25
24
OPEN_EXPANSION_PANEL ,
26
25
DELETE_PROP ,
27
26
ADD_PROP ,
28
27
DELETE_ALL_DATA ,
29
- CHANGE_IMAGE_PATH
30
- } from " ../actionTypes/index" ;
28
+ CHANGE_IMAGE_PATH ,
29
+ } from ' ../actionTypes/index' ;
31
30
32
- import { loadState } from " ../localStorage" ;
31
+ import { loadState } from ' ../localStorage' ;
33
32
34
33
// import createFiles from '../utils/createFiles.util';
35
34
// import createApplicationUtil from '../utils/createApplication.util';
36
35
37
- export const loadInitData = ( ) => dispatch => {
38
- loadState ( ) . then ( data =>
39
- dispatch ( {
40
- type : LOAD_INIT_DATA ,
41
- payload : {
42
- data : data ? data . workspace : { }
43
- }
44
- } )
45
- ) ;
36
+ export const loadInitData = ( ) => ( dispatch ) => {
37
+ loadState ( ) . then ( data => dispatch ( {
38
+ type : LOAD_INIT_DATA ,
39
+ payload : {
40
+ data : data ? data . workspace : { } ,
41
+ } ,
42
+ } ) ) ;
46
43
} ;
47
44
48
45
export const updateChildren = ( { parentIds, childIndex, childId } ) => ( {
49
46
type : UPDATE_CHILDREN ,
50
47
payload : {
51
48
parentIds,
52
49
childIndex,
53
- childId
54
- }
50
+ childId,
51
+ } ,
55
52
} ) ;
56
53
57
54
export const parentReassignment = ( { index, id, parentIds } ) => ( {
58
55
type : REASSIGN_PARENT ,
59
56
payload : {
60
57
index,
61
58
id,
62
- parentIds
63
- }
59
+ parentIds,
60
+ } ,
64
61
} ) ;
65
62
66
- export const addComponent = ( { title } ) => dispatch => {
63
+ export const addComponent = ( { title } ) => ( dispatch ) => {
67
64
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
68
65
} ;
69
66
70
- export const addChild = ( { title } ) => dispatch => {
67
+ export const addChild = ( { title } ) => ( dispatch ) => {
71
68
dispatch ( { type : ADD_CHILD , payload : { title } } ) ;
72
69
} ;
73
70
74
- export const deleteChild = ( { } ) => dispatch => {
71
+ export const deleteChild = ( { } ) => ( dispatch ) => {
75
72
// with no payload, it will delete focusd child
76
73
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
77
74
} ;
78
75
79
- export const deleteComponent = ( {
80
- componentId,
81
- stateComponents
82
- } ) => dispatch => {
83
- console . log (
84
- "Hello from component.js delete component.componentId= " ,
85
- componentId
86
- ) ;
76
+ export const deleteComponent = ( { componentId, stateComponents } ) => ( dispatch ) => {
77
+ console . log ( 'Hello from component.js delete component.componentId= ' , componentId ) ;
87
78
88
79
// find all places where the "to be delted" is a child and do what u gotta do
89
- stateComponents . forEach ( parent => {
90
- parent . childrenArray
91
- . filter ( child => child . childComponentId == componentId )
92
- . forEach ( child => {
93
- // console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
94
- dispatch ( {
95
- type : DELETE_CHILD ,
96
- payload : {
97
- parentId : parent . id ,
98
- childId : child . childId ,
99
- calledFromDeleteComponent : true
100
- }
101
- } ) ;
80
+ stateComponents . forEach ( ( parent ) => {
81
+ parent . childrenArray . filter ( child => child . childComponentId == componentId ) . forEach ( ( child ) => {
82
+ // console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
83
+ dispatch ( {
84
+ type : DELETE_CHILD ,
85
+ payload : {
86
+ parentId : parent . id ,
87
+ childId : child . childId ,
88
+ calledFromDeleteComponent : true ,
89
+ } ,
102
90
} ) ;
91
+ } ) ;
103
92
} ) ;
104
93
105
94
// change focus to APp
106
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
95
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
107
96
// after taking care of the children delete the component
108
97
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
109
98
} ;
@@ -113,48 +102,45 @@ export const updateComponent = ({
113
102
index,
114
103
newParentId = null ,
115
104
color = null ,
116
- stateful = null
117
- } ) => dispatch => {
105
+ stateful = null ,
106
+ } ) => ( dispatch ) => {
118
107
dispatch ( {
119
108
type : UPDATE_COMPONENT ,
120
109
payload : {
121
110
id,
122
111
index,
123
112
newParentId,
124
113
color,
125
- stateful
126
- }
114
+ stateful,
115
+ } ,
127
116
} ) ;
128
117
129
118
if ( newParentId ) {
130
119
dispatch (
131
120
updateChildren ( {
132
121
parentIds : [ newParentId ] ,
133
122
childId : id ,
134
- childIndex : index
135
- } )
123
+ childIndex : index ,
124
+ } ) ,
136
125
) ;
137
126
}
138
127
139
128
dispatch ( { type : SET_SELECTABLE_PARENTS } ) ;
140
129
} ;
141
130
142
- export const changeFocusComponent = ( { title } ) => dispatch => {
131
+ export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
143
132
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
144
133
} ;
145
134
146
135
// make sure childId is being sent in
147
- export const changeFocusChild = ( { title, childId } ) => dispatch => {
136
+ export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
148
137
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
149
138
} ;
150
139
151
- export const changeComponentFocusChild = ( {
152
- componentId,
153
- childId
154
- } ) => dispatch => {
140
+ export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
155
141
dispatch ( {
156
142
type : CHANGE_COMPONENT_FOCUS_CHILD ,
157
- payload : { componentId, childId }
143
+ payload : { componentId, childId } ,
158
144
} ) ;
159
145
} ;
160
146
@@ -176,23 +162,21 @@ export const changeComponentFocusChild = ({
176
162
177
163
export const handleClose = ( ) => ( {
178
164
type : HANDLE_CLOSE ,
179
- payload : false
165
+ payload : false ,
180
166
} ) ;
181
167
182
- export const handleTransform = (
183
- componentId ,
184
- childId ,
185
- { x, y, width, height }
186
- ) => ( {
168
+ export const handleTransform = ( componentId , childId , {
169
+ x, y, width, height,
170
+ } ) => ( {
187
171
type : HANDLE_TRANSFORM ,
188
172
payload : {
189
173
componentId,
190
174
childId,
191
175
x,
192
176
y,
193
177
width,
194
- height
195
- }
178
+ height,
179
+ } ,
196
180
} ) ;
197
181
198
182
// export const createApplication = ({
@@ -220,41 +204,21 @@ export const handleTransform = (
220
204
// }
221
205
// };
222
206
223
- export const toggleDragging = status => ( {
224
- type : TOGGLE_DRAGGING ,
225
- payload : status
226
- } ) ;
227
-
228
- // export const moveToBottom = componentId => ({
229
- // type: MOVE_TO_BOTTOM,
230
- // payload: componentId,
231
- // });
232
-
233
- // export const moveToTop = componentId => ({
234
- // type: MOVE_TO_TOP,
235
- // payload: componentId,
236
- // });
237
-
238
207
export const openExpansionPanel = component => ( {
239
208
type : OPEN_EXPANSION_PANEL ,
240
- payload : { component }
209
+ payload : { component } ,
241
210
} ) ;
242
211
243
212
// export const deleteAllData = () => ({
244
213
// type: DELETE_ALL_DATA,
245
214
// });
246
215
247
- // export const changeImagePath = path => ({
248
- // type: CHANGE_IMAGE_PATH,
249
- // payload: path,
250
- // });
251
-
252
216
export const deleteProp = ( { id, index } ) => ( {
253
217
type : DELETE_PROP ,
254
- payload : { id, index }
218
+ payload : { id, index } ,
255
219
} ) ;
256
220
257
221
export const addProp = prop => ( {
258
222
type : ADD_PROP ,
259
- payload : { ...prop }
223
+ payload : { ...prop } ,
260
224
} ) ;
0 commit comments