3
3
ComponentsInt ,
4
4
PropInt ,
5
5
ChildInt ,
6
- Action ,
6
+ Action
7
7
} from '../utils/Interfaces' ;
8
8
9
9
import {
@@ -36,6 +36,7 @@ import {
36
36
CHANGE_TUTORIAL ,
37
37
UNDO ,
38
38
REDO ,
39
+ UPDATE_CODE ,
39
40
EDIT_MODE ,
40
41
EDIT_COMPONENT
41
42
} from '../actionTypes/index' ;
@@ -46,12 +47,12 @@ import createApplicationUtil from '../utils/createApplication.util';
46
47
47
48
export const changeTutorial = ( tutorial : number ) => ( {
48
49
type : CHANGE_TUTORIAL ,
49
- payload : { tutorial } ,
50
+ payload : { tutorial }
50
51
} ) ;
51
52
52
53
export const changeImagePath = ( imageSource : string ) => ( {
53
54
type : CHANGE_IMAGE_SOURCE ,
54
- payload : { imageSource } ,
55
+ payload : { imageSource }
55
56
} ) ;
56
57
57
58
export const loadInitData = ( ) => ( dispatch : ( arg : Action ) => void ) => {
@@ -61,8 +62,8 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
61
62
payload : {
62
63
data : data
63
64
? { ...data . workspace , history : [ ] , historyIndex : 0 , future : [ ] } //erase history upon opening app
64
- : { } ,
65
- } ,
65
+ : { }
66
+ }
66
67
} ) ;
67
68
} ) ;
68
69
} ;
@@ -76,7 +77,7 @@ export const addComponent = ({ title }: { title: string }) => (
76
77
export const addChild = ( {
77
78
title,
78
79
childType,
79
- HTMLInfo,
80
+ HTMLInfo
80
81
} : {
81
82
title : string ;
82
83
childType : string ;
@@ -92,7 +93,7 @@ export const deleteChild = ({}) => (dispatch: (arg: Action) => void) => {
92
93
93
94
export const deleteComponent = ( {
94
95
componentId,
95
- stateComponents,
96
+ stateComponents
96
97
} : {
97
98
componentId : number ;
98
99
stateComponents : ComponentsInt ;
@@ -107,8 +108,8 @@ export const deleteComponent = ({
107
108
payload : {
108
109
parentId : parent . id ,
109
110
childId : child . childId ,
110
- calledFromDeleteComponent : true ,
111
- } ,
111
+ calledFromDeleteComponent : true
112
+ }
112
113
} ) ;
113
114
} ) ;
114
115
} ) ;
@@ -134,26 +135,38 @@ export const changeFocusChild = ({ childId }: { childId: number }) => (
134
135
135
136
export const changeComponentFocusChild = ( {
136
137
componentId,
137
- childId,
138
+ childId
138
139
} : {
139
140
componentId : number ;
140
141
childId : number ;
141
142
} ) => ( dispatch : ( arg : Action ) => void ) => {
142
143
dispatch ( {
143
144
type : CHANGE_COMPONENT_FOCUS_CHILD ,
144
- payload : { componentId, childId } ,
145
+ payload : { componentId, childId }
145
146
} ) ;
146
147
} ;
147
148
148
149
export const deleteImage = ( ) => ( {
149
- type : DELETE_IMAGE ,
150
+ type : DELETE_IMAGE
150
151
} ) ;
151
152
153
+ export const updateCode = ( {
154
+ componentId,
155
+ code
156
+ } : {
157
+ componentId : number ;
158
+ code : string ;
159
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
160
+ dispatch ( {
161
+ type : UPDATE_CODE ,
162
+ payload : { componentId, code }
163
+ } ) ;
164
+ } ;
152
165
export const exportFiles = ( {
153
166
components,
154
167
path,
155
168
appName,
156
- exportAppBool,
169
+ exportAppBool
157
170
} : {
158
171
components : ComponentsInt ;
159
172
path : string ;
@@ -162,26 +175,26 @@ export const exportFiles = ({
162
175
} ) => ( dispatch : ( arg : Action ) => void ) => {
163
176
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
164
177
dispatch ( {
165
- type : EXPORT_FILES ,
178
+ type : EXPORT_FILES
166
179
} ) ;
167
180
createFiles ( components , path , appName , exportAppBool )
168
181
. then ( ( dir : any ) =>
169
182
dispatch ( {
170
183
type : EXPORT_FILES_SUCCESS ,
171
- payload : { status : true , dir : dir [ 0 ] } ,
184
+ payload : { status : true , dir : dir [ 0 ] }
172
185
} )
173
186
)
174
187
. catch ( ( err : string ) =>
175
188
dispatch ( {
176
189
type : EXPORT_FILES_ERROR ,
177
- payload : { status : true , err } ,
190
+ payload : { status : true , err }
178
191
} )
179
192
) ;
180
193
} ;
181
194
182
195
export const handleClose = ( ) => ( {
183
196
type : HANDLE_CLOSE ,
184
- payload : false ,
197
+ payload : false
185
198
} ) ;
186
199
187
200
export const handleTransform = (
@@ -191,7 +204,7 @@ export const handleTransform = (
191
204
x,
192
205
y,
193
206
width,
194
- height,
207
+ height
195
208
} : { x : number ; y : number ; width : number ; height : number }
196
209
) => ( {
197
210
type : HANDLE_TRANSFORM ,
@@ -201,16 +214,16 @@ export const handleTransform = (
201
214
x,
202
215
y,
203
216
width,
204
- height,
205
- } ,
217
+ height
218
+ }
206
219
} ) ;
207
220
208
221
export const createApplication = ( {
209
222
path,
210
223
components = [ ] ,
211
224
genOption,
212
225
appName = 'reactype_app' ,
213
- exportAppBool,
226
+ exportAppBool
214
227
} : {
215
228
path : string ;
216
229
components : ComponentsInt ;
@@ -225,48 +238,48 @@ export const createApplication = ({
225
238
appName,
226
239
path,
227
240
components,
228
- exportAppBool,
241
+ exportAppBool
229
242
} )
230
243
) ;
231
244
} else if ( genOption ) {
232
245
exportAppBool = true ;
233
246
dispatch ( {
234
- type : CREATE_APPLICATION ,
247
+ type : CREATE_APPLICATION
235
248
} ) ;
236
249
createApplicationUtil ( {
237
250
path,
238
251
appName,
239
- genOption,
252
+ genOption
240
253
} )
241
254
. then ( ( ) => {
242
255
dispatch ( {
243
- type : CREATE_APPLICATION_SUCCESS ,
256
+ type : CREATE_APPLICATION_SUCCESS
244
257
} ) ;
245
258
dispatch (
246
259
exportFiles ( {
247
260
appName,
248
261
path,
249
262
components,
250
- exportAppBool,
263
+ exportAppBool
251
264
} )
252
265
) ;
253
266
} )
254
267
. catch ( ( err : string ) =>
255
268
dispatch ( {
256
269
type : CREATE_APPLICATION_ERROR ,
257
- payload : { status : true , err } ,
270
+ payload : { status : true , err }
258
271
} )
259
272
) ;
260
273
}
261
274
} ;
262
275
263
276
export const openExpansionPanel = ( component : ComponentInt ) => ( {
264
277
type : OPEN_EXPANSION_PANEL ,
265
- payload : { component } ,
278
+ payload : { component }
266
279
} ) ;
267
280
268
281
export const deleteAllData = ( ) => ( {
269
- type : DELETE_ALL_DATA ,
282
+ type : DELETE_ALL_DATA
270
283
} ) ;
271
284
272
285
export const deleteProp = ( propId : number ) => (
@@ -289,16 +302,16 @@ export const toggleComponentClass = ({ id }: { id: number }) => (
289
302
290
303
export const addProp = ( prop : PropInt ) => ( {
291
304
type : ADD_PROP ,
292
- payload : { ...prop } ,
305
+ payload : { ...prop }
293
306
} ) ;
294
307
295
308
//action creators for undo and redo
296
309
export const undo = ( ) => ( {
297
- type : UNDO ,
310
+ type : UNDO
298
311
} ) ;
299
312
300
313
export const redo = ( ) => ( {
301
- type : REDO ,
314
+ type : REDO
302
315
} ) ;
303
316
304
317
export const toggleEditMode = ( { id } : { id : number } ) => (
@@ -307,23 +320,22 @@ export const toggleEditMode = ({ id }: { id: number }) => (
307
320
dispatch ( { type : EDIT_MODE , payload : { id } } ) ;
308
321
} ;
309
322
310
- export const editComponent = ( { id, title } : { id : number , title : string } ) => (
323
+ export const editComponent = ( { id, title } : { id : number ; title : string } ) => (
311
324
dispatch : ( arg : Action ) => void
312
325
) => {
313
- dispatch ( { type : EDIT_COMPONENT , payload : { id, title } } ) ;
326
+ dispatch ( { type : EDIT_COMPONENT , payload : { id, title } } ) ;
314
327
} ;
315
-
316
328
317
329
export const updateHtmlAttr = ( {
318
330
attr,
319
- value,
331
+ value
320
332
} : {
321
333
attr : string ;
322
334
value : string ;
323
335
} ) => ( dispatch : ( arg : Action ) => void ) => {
324
336
dispatch ( {
325
337
type : UPDATE_HTML_ATTR ,
326
- payload : { attr, value } ,
338
+ payload : { attr, value }
327
339
} ) ;
328
340
} ;
329
341
0 commit comments