@@ -25,23 +25,21 @@ import {
25
25
DELETE_PROP ,
26
26
ADD_PROP ,
27
27
DELETE_ALL_DATA ,
28
- CHANGE_IMAGE_PATH
29
- } from " ../actionTypes/index" ;
28
+ CHANGE_IMAGE_PATH ,
29
+ } from ' ../actionTypes/index' ;
30
30
31
- import { loadState } from " ../localStorage" ;
31
+ import { loadState } from ' ../localStorage' ;
32
32
33
33
import createFiles from '../utils/createFiles.util' ;
34
- import createApplicationUtil from '../utils/createApplication.util'
35
-
36
- export const loadInitData = ( ) => dispatch => {
37
- loadState ( ) . then ( data =>
38
- dispatch ( {
39
- type : LOAD_INIT_DATA ,
40
- payload : {
41
- data : data ? data . workspace : { }
42
- }
43
- } )
44
- ) ;
34
+ import createApplicationUtil from '../utils/createApplication.util' ;
35
+
36
+ export const loadInitData = ( ) => ( dispatch ) => {
37
+ loadState ( ) . then ( data => dispatch ( {
38
+ type : LOAD_INIT_DATA ,
39
+ payload : {
40
+ data : data ? data . workspace : { } ,
41
+ } ,
42
+ } ) ) ;
45
43
} ;
46
44
47
45
// export const updateChildren = ({ parentIds, childIndex, childId }) => ({
@@ -62,47 +60,39 @@ export const loadInitData = () => dispatch => {
62
60
// },
63
61
// });
64
62
65
- export const addComponent = ( { title } ) => dispatch => {
63
+ export const addComponent = ( { title } ) => ( dispatch ) => {
66
64
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
67
65
} ;
68
66
69
- export const addChild = ( { title, childType, HTMLInfo } ) => dispatch => {
67
+ export const addChild = ( { title, childType, HTMLInfo } ) => ( dispatch ) => {
70
68
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
71
69
} ;
72
70
73
- export const deleteChild = ( { } ) => dispatch => {
71
+ export const deleteChild = ( { } ) => ( dispatch ) => {
74
72
// with no payload, it will delete focusd child
75
73
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
76
74
} ;
77
75
78
- export const deleteComponent = ( {
79
- componentId,
80
- stateComponents
81
- } ) => dispatch => {
82
- console . log (
83
- "Hello from component.js delete component.componentId= " ,
84
- componentId
85
- ) ;
76
+ export const deleteComponent = ( { componentId, stateComponents } ) => ( dispatch ) => {
77
+ console . log ( 'Hello from component.js delete component.componentId= ' , componentId ) ;
86
78
87
79
// find all places where the "to be delted" is a child and do what u gotta do
88
- stateComponents . forEach ( parent => {
89
- parent . childrenArray
90
- . filter ( child => child . childComponentId == componentId )
91
- . forEach ( child => {
92
- // console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
93
- dispatch ( {
94
- type : DELETE_CHILD ,
95
- payload : {
96
- parentId : parent . id ,
97
- childId : child . childId ,
98
- calledFromDeleteComponent : true
99
- }
100
- } ) ;
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
+ } ,
101
90
} ) ;
91
+ } ) ;
102
92
} ) ;
103
93
104
94
// change focus to APp
105
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
95
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
106
96
// after taking care of the children delete the component
107
97
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
108
98
} ;
@@ -138,22 +128,19 @@ export const deleteComponent = ({
138
128
// dispatch({ type: SET_SELECTABLE_PARENTS });
139
129
// };
140
130
141
- export const changeFocusComponent = ( { title } ) => dispatch => {
131
+ export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
142
132
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
143
133
} ;
144
134
145
135
// make sure childId is being sent in
146
- export const changeFocusChild = ( { title, childId } ) => dispatch => {
136
+ export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
147
137
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
148
138
} ;
149
139
150
- export const changeComponentFocusChild = ( {
151
- componentId,
152
- childId
153
- } ) => dispatch => {
140
+ export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
154
141
dispatch ( {
155
142
type : CHANGE_COMPONENT_FOCUS_CHILD ,
156
- payload : { componentId, childId }
143
+ payload : { componentId, childId } ,
157
144
} ) ;
158
145
} ;
159
146
@@ -175,27 +162,29 @@ export const exportFiles = ({ components, path }) => (dispatch) => {
175
162
176
163
export const handleClose = ( ) => ( {
177
164
type : HANDLE_CLOSE ,
178
- payload : false
165
+ payload : false ,
179
166
} ) ;
180
167
181
- export const handleTransform = (
182
- componentId ,
183
- childId ,
184
- { x, y, width, height }
185
- ) => ( {
168
+ export const handleTransform = ( componentId , childId , {
169
+ x, y, width, height,
170
+ } ) => ( {
186
171
type : HANDLE_TRANSFORM ,
187
172
payload : {
188
173
componentId,
189
174
childId,
190
175
x,
191
176
y,
192
177
width,
193
- height
194
- }
178
+ height,
179
+ } ,
195
180
} ) ;
196
181
197
182
export const createApplication = ( {
198
- path, components = [ ] , genOption, appName = 'proto_app' , repoUrl,
183
+ path,
184
+ components = [ ] ,
185
+ genOption,
186
+ appName = 'proto_app' ,
187
+ repoUrl,
199
188
} ) => ( dispatch ) => {
200
189
if ( genOption === 0 ) {
201
190
dispatch ( exportFiles ( { path, components } ) ) ;
@@ -204,7 +193,10 @@ export const createApplication = ({
204
193
type : CREATE_APPLICATION ,
205
194
} ) ;
206
195
createApplicationUtil ( {
207
- path, appName, genOption, repoUrl,
196
+ path,
197
+ appName,
198
+ genOption,
199
+ repoUrl,
208
200
} )
209
201
. then ( ( ) => {
210
202
dispatch ( {
@@ -221,18 +213,18 @@ export const createApplication = ({
221
213
222
214
export const openExpansionPanel = component => ( {
223
215
type : OPEN_EXPANSION_PANEL ,
224
- payload : { component }
216
+ payload : { component } ,
225
217
} ) ;
226
218
227
219
// export const deleteAllData = () => ({
228
220
// type: DELETE_ALL_DATA,
229
221
// });
230
222
231
- export const deleteProp = propId => dispatch => {
223
+ export const deleteProp = propId => ( dispatch ) => {
232
224
dispatch ( { type : DELETE_PROP , payload : propId } ) ;
233
225
} ;
234
226
235
227
export const addProp = prop => ( {
236
228
type : ADD_PROP ,
237
- payload : { ...prop }
229
+ payload : { ...prop } ,
238
230
} ) ;
0 commit comments