@@ -26,23 +26,21 @@ import {
26
26
ADD_PROP ,
27
27
DELETE_ALL_DATA ,
28
28
CHANGE_IMAGE_PATH ,
29
- UPDATE_HTML_ATTR
30
- } from " ../actionTypes/index" ;
29
+ UPDATE_HTML_ATTR ,
30
+ } from ' ../actionTypes/index' ;
31
31
32
- import { loadState } from " ../localStorage" ;
32
+ import { loadState } from ' ../localStorage' ;
33
33
34
- import createFiles from " ../utils/createFiles.util" ;
35
- import createApplicationUtil from " ../utils/createApplication.util" ;
34
+ import createFiles from ' ../utils/createFiles.util' ;
35
+ import createApplicationUtil from ' ../utils/createApplication.util' ;
36
36
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
- ) ;
37
+ export const loadInitData = ( ) => ( dispatch ) => {
38
+ loadState ( ) . then ( data => dispatch ( {
39
+ type : LOAD_INIT_DATA ,
40
+ payload : {
41
+ data : data ? data . workspace : { } ,
42
+ } ,
43
+ } ) ) ;
46
44
} ;
47
45
48
46
// export const updateChildren = ({ parentIds, childIndex, childId }) => ({
@@ -63,47 +61,36 @@ export const loadInitData = () => dispatch => {
63
61
// },
64
62
// });
65
63
66
- export const addComponent = ( { title } ) => dispatch => {
64
+ export const addComponent = ( { title } ) => ( dispatch ) => {
67
65
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
68
66
} ;
69
67
70
- export const addChild = ( { title, childType, HTMLInfo } ) => dispatch => {
68
+ export const addChild = ( { title, childType, HTMLInfo } ) => ( dispatch ) => {
71
69
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
72
70
} ;
73
71
74
- export const deleteChild = ( { } ) => dispatch => {
72
+ export const deleteChild = ( { } ) => ( dispatch ) => {
75
73
// with no payload, it will delete focusd child
76
74
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
77
75
} ;
78
76
79
- export const deleteComponent = ( {
80
- componentId,
81
- stateComponents
82
- } ) => dispatch => {
83
- console . log (
84
- "Hello from component.js delete component.componentId= " ,
85
- componentId
86
- ) ;
87
-
77
+ export const deleteComponent = ( { componentId, stateComponents } ) => ( dispatch ) => {
88
78
// 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
- } ) ;
79
+ stateComponents . forEach ( ( parent ) => {
80
+ parent . childrenArray . filter ( child => child . childComponentId == componentId ) . forEach ( ( child ) => {
81
+ dispatch ( {
82
+ type : DELETE_CHILD ,
83
+ payload : {
84
+ parentId : parent . id ,
85
+ childId : child . childId ,
86
+ calledFromDeleteComponent : true ,
87
+ } ,
102
88
} ) ;
89
+ } ) ;
103
90
} ) ;
104
91
105
92
// change focus to APp
106
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
93
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
107
94
// after taking care of the children delete the component
108
95
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
109
96
} ;
@@ -139,143 +126,129 @@ export const deleteComponent = ({
139
126
// dispatch({ type: SET_SELECTABLE_PARENTS });
140
127
// };
141
128
142
- export const changeFocusComponent = ( { title } ) => dispatch => {
129
+ export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
143
130
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
144
131
} ;
145
132
146
133
// make sure childId is being sent in
147
- export const changeFocusChild = ( { title, childId } ) => dispatch => {
134
+ export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
148
135
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
149
136
} ;
150
137
151
- export const changeComponentFocusChild = ( {
152
- componentId,
153
- childId
154
- } ) => dispatch => {
138
+ export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
155
139
dispatch ( {
156
140
type : CHANGE_COMPONENT_FOCUS_CHILD ,
157
- payload : { componentId, childId }
141
+ payload : { componentId, childId } ,
158
142
} ) ;
159
143
} ;
160
144
161
145
export const exportFiles = ( {
162
- components,
163
- path,
164
- appName,
165
- exportAppBool
166
- } ) => dispatch => {
146
+ components, path, appName, exportAppBool,
147
+ } ) => ( dispatch ) => {
167
148
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
168
149
dispatch ( {
169
- type : EXPORT_FILES
150
+ type : EXPORT_FILES ,
170
151
} ) ;
171
152
172
153
createFiles ( components , path , appName , exportAppBool )
173
- . then ( dir =>
174
- dispatch ( {
175
- type : EXPORT_FILES_SUCCESS ,
176
- payload : { status : true , dir : dir [ 0 ] }
177
- } )
178
- )
179
- . catch ( err =>
180
- dispatch ( {
181
- type : EXPORT_FILES_ERROR ,
182
- payload : { status : true , err }
183
- } )
184
- ) ;
154
+ . then ( dir => dispatch ( {
155
+ type : EXPORT_FILES_SUCCESS ,
156
+ payload : { status : true , dir : dir [ 0 ] } ,
157
+ } ) )
158
+ . catch ( err => dispatch ( {
159
+ type : EXPORT_FILES_ERROR ,
160
+ payload : { status : true , err } ,
161
+ } ) ) ;
185
162
} ;
186
163
187
164
export const handleClose = ( ) => ( {
188
165
type : HANDLE_CLOSE ,
189
- payload : false
166
+ payload : false ,
190
167
} ) ;
191
168
192
- export const handleTransform = (
193
- componentId ,
194
- childId ,
195
- { x, y, width, height }
196
- ) => ( {
169
+ export const handleTransform = ( componentId , childId , {
170
+ x, y, width, height,
171
+ } ) => ( {
197
172
type : HANDLE_TRANSFORM ,
198
173
payload : {
199
174
componentId,
200
175
childId,
201
176
x,
202
177
y,
203
178
width,
204
- height
205
- }
179
+ height,
180
+ } ,
206
181
} ) ;
207
182
208
183
export const createApplication = ( {
209
184
path,
210
185
components = [ ] ,
211
186
genOption,
212
- appName = " reactype_app" ,
213
- exportAppBool
214
- } ) => dispatch => {
187
+ appName = ' reactype_app' ,
188
+ exportAppBool,
189
+ } ) => ( dispatch ) => {
215
190
if ( genOption === 0 ) {
216
191
exportAppBool = false ;
217
192
dispatch (
218
193
exportFiles ( {
219
194
appName,
220
195
path,
221
196
components,
222
- exportAppBool
223
- } )
197
+ exportAppBool,
198
+ } ) ,
224
199
) ;
225
200
} else if ( genOption ) {
226
201
exportAppBool = true ;
227
202
dispatch ( {
228
- type : CREATE_APPLICATION
203
+ type : CREATE_APPLICATION ,
229
204
} ) ;
230
205
createApplicationUtil ( {
231
206
path,
232
207
appName,
233
208
genOption,
234
- exportAppBool
209
+ exportAppBool,
235
210
} )
236
211
. then ( ( ) => {
237
212
dispatch ( {
238
- type : CREATE_APPLICATION_SUCCESS
213
+ type : CREATE_APPLICATION_SUCCESS ,
239
214
} ) ;
240
215
dispatch (
241
216
exportFiles ( {
242
217
appName,
243
218
path,
244
219
components,
245
- exportAppBool
246
- } )
220
+ exportAppBool,
221
+ } ) ,
247
222
) ;
248
223
} )
249
- . catch ( err =>
250
- dispatch ( {
251
- type : CREATE_APPLICATION_ERROR ,
252
- payload : { status : true , err }
253
- } )
254
- ) ;
224
+ . catch ( err => dispatch ( {
225
+ type : CREATE_APPLICATION_ERROR ,
226
+ payload : { status : true , err } ,
227
+ } ) ) ;
255
228
}
256
229
} ;
257
230
258
231
export const openExpansionPanel = component => ( {
259
232
type : OPEN_EXPANSION_PANEL ,
260
- payload : { component }
233
+ payload : { component } ,
261
234
} ) ;
262
235
263
236
// export const deleteAllData = () => ({
264
237
// type: DELETE_ALL_DATA,
265
238
// });
266
239
267
- export const deleteProp = propId => dispatch => {
240
+ export const deleteProp = propId => ( dispatch ) => {
268
241
dispatch ( { type : DELETE_PROP , payload : propId } ) ;
269
242
} ;
270
243
271
244
export const addProp = prop => ( {
272
245
type : ADD_PROP ,
273
- payload : { ...prop }
246
+ payload : { ...prop } ,
274
247
} ) ;
275
248
276
- export const updateHtmlAttr = ( { attr, value } ) => dispatch => {
249
+ export const updateHtmlAttr = ( { attr, value } ) => ( dispatch ) => {
277
250
dispatch ( {
278
251
type : UPDATE_HTML_ATTR ,
279
- payload : { attr, value }
252
+ payload : { attr, value } ,
280
253
} ) ;
281
254
} ;
0 commit comments