1
1
import {
2
- ComponentInt ,
3
- ComponentsInt ,
4
- PropInt ,
5
- ChildInt
2
+ ComponentInt , ComponentsInt , PropInt , ChildInt , Action , ApplicationStateInt
6
3
} from '../utils/Interfaces.ts' ;
7
4
8
5
import {
@@ -32,32 +29,30 @@ import {
32
29
UPDATE_CHILDREN_SORT ,
33
30
CHANGE_IMAGE_SOURCE ,
34
31
DELETE_IMAGE
35
-
36
- } from '../actionTypes/index.js' ;
32
+ } from '../actionTypes/index.ts' ;
37
33
38
34
import { loadState } from '../localStorage' ;
39
35
import createFiles from '../utils/createFiles.util.ts' ;
40
36
import createApplicationUtil from '../utils/createApplication.util.ts' ;
41
37
38
+
42
39
export const changeImagePath = ( imageSource : string ) => ( {
43
40
type : CHANGE_IMAGE_SOURCE ,
44
- payload : imageSource ,
41
+ payload : { imageSource } ,
45
42
} )
46
43
47
- export const loadInitData = ( ) => ( dispatch : any ) => {
48
- loadState ( ) . then ( ( data : any ) =>
44
+ export const loadInitData = ( ) => ( dispatch : ( arg : Action ) => void ) => {
45
+ loadState ( ) . then ( ( data : ApplicationStateInt ) => {
49
46
dispatch ( {
50
- type : LOAD_INIT_DATA ,
51
- payload : {
52
- data : data ? data . workspace : { }
53
- }
54
- } )
55
- ) ;
47
+ type : LOAD_INIT_DATA ,
48
+ payload : {
49
+ data : data ? data . workspace : { } ,
50
+ } ,
51
+ } ) ;
52
+ } ) ;
56
53
} ;
57
54
58
- export const addComponent = ( { title } : { title : string } ) => (
59
- dispatch : any
60
- ) => {
55
+ export const addComponent = ( { title } : { title : string } ) => ( dispatch : ( arg : Action ) => void ) => {
61
56
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
62
57
} ;
63
58
@@ -66,14 +61,14 @@ export const addChild = ({
66
61
childType,
67
62
HTMLInfo
68
63
} : {
69
- title : string ;
70
- childType : string ;
71
- HTMLInfo : object ;
72
- } ) => ( dispatch : any ) => {
64
+ title : string ;
65
+ childType : string ;
66
+ HTMLInfo : object ;
67
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
73
68
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
74
69
} ;
75
70
76
- export const deleteChild = ( { } ) => ( dispatch : any ) => {
71
+ export const deleteChild = ( { } ) => ( dispatch : ( arg : Action ) => void ) => {
77
72
// with no payload, it will delete focusd child
78
73
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
79
74
} ;
@@ -82,9 +77,9 @@ export const deleteComponent = ({
82
77
componentId,
83
78
stateComponents
84
79
} : {
85
- componentId : number ;
86
- stateComponents : ComponentsInt ;
87
- } ) => ( dispatch : any ) => {
80
+ componentId : number ;
81
+ stateComponents : ComponentsInt ;
82
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
88
83
// find all places where the "to be deleted" is a child and do what u gotta do
89
84
stateComponents . forEach ( ( parent : ComponentInt ) => {
90
85
parent . childrenArray
@@ -107,35 +102,30 @@ export const deleteComponent = ({
107
102
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
108
103
} ;
109
104
110
- export const changeFocusComponent = ( { title } : { title : string } ) => (
111
- dispatch : any
112
- ) => {
105
+ export const changeFocusComponent = ( { title } : { title : string } ) => ( dispatch : ( arg : Action ) => void ) => {
113
106
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
114
107
} ;
115
108
116
109
// make sure childId is being sent in
117
- export const changeFocusChild = ( { childId } : { childId : number } ) => (
118
- dispatch : any
119
- ) => {
110
+ export const changeFocusChild = ( { childId } : { childId : number } ) => ( dispatch : ( arg : Action ) => void ) => {
120
111
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { childId } } ) ;
121
112
} ;
122
113
123
114
export const changeComponentFocusChild = ( {
124
115
componentId,
125
116
childId
126
117
} : {
127
- componentId : number ;
128
- childId : number ;
129
- } ) => ( dispatch : any ) => {
118
+ componentId : number ;
119
+ childId : number ;
120
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
130
121
dispatch ( {
131
122
type : CHANGE_COMPONENT_FOCUS_CHILD ,
132
123
payload : { componentId, childId }
133
124
} ) ;
134
125
} ;
135
126
136
127
export const deleteImage = ( ) => ( {
137
- type : DELETE_IMAGE ,
138
- payload : ''
128
+ type : DELETE_IMAGE
139
129
} )
140
130
141
131
@@ -145,11 +135,11 @@ export const exportFiles = ({
145
135
appName,
146
136
exportAppBool
147
137
} : {
148
- components : ComponentsInt ;
149
- path : string ;
150
- appName : string ;
151
- exportAppBool : boolean ;
152
- } ) => ( dispatch : any ) => {
138
+ components : ComponentsInt ;
139
+ path : string ;
140
+ appName : string ;
141
+ exportAppBool : boolean ;
142
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
153
143
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
154
144
dispatch ( {
155
145
type : EXPORT_FILES
@@ -203,12 +193,12 @@ export const createApplication = ({
203
193
appName = 'reactype_app' ,
204
194
exportAppBool
205
195
} : {
206
- path : string ;
207
- components : ComponentsInt ;
208
- genOption : number ;
209
- appName : string ;
210
- exportAppBool : boolean ;
211
- } ) => ( dispatch : any ) => {
196
+ path : string ;
197
+ components : ComponentsInt ;
198
+ genOption : number ;
199
+ appName : string ;
200
+ exportAppBool : boolean ;
201
+ } ) => ( dispatch : ( arg : Action ) => void ) => {
212
202
if ( genOption === 0 ) {
213
203
exportAppBool = false ;
214
204
dispatch (
@@ -227,8 +217,7 @@ export const createApplication = ({
227
217
createApplicationUtil ( {
228
218
path,
229
219
appName,
230
- genOption
231
- // exportAppBool
220
+ genOption,
232
221
} )
233
222
. then ( ( ) => {
234
223
dispatch ( {
@@ -261,7 +250,7 @@ export const deleteAllData = () => ({
261
250
type : DELETE_ALL_DATA
262
251
} ) ;
263
252
264
- export const deleteProp = ( propId : number ) => ( dispatch : any ) => {
253
+ export const deleteProp = ( propId : number ) => ( dispatch : ( arg : Action ) => void ) => {
265
254
dispatch ( { type : DELETE_PROP , payload : propId } ) ;
266
255
} ;
267
256
@@ -274,26 +263,21 @@ export const addProp = (prop: PropInt) => ({
274
263
payload : { ...prop }
275
264
} ) ;
276
265
277
- export const updateHtmlAttr = ( {
278
- attr,
279
- value
280
- } : {
281
- attr : string ;
282
- value : string ;
283
- } ) => ( dispatch : any ) => {
266
+ export const updateHtmlAttr = ( { attr, value } : { attr : string ; value : string } ) => (
267
+ dispatch : ( arg : Action ) => void ,
268
+ ) => {
284
269
dispatch ( {
285
270
type : UPDATE_HTML_ATTR ,
286
271
payload : { attr, value }
287
272
} ) ;
288
273
} ;
289
274
290
- export const updateChildrenSort = ( {
291
- newSortValues
292
- } : {
293
- newSortValues : any ;
294
- } ) => ( dispatch : any ) => {
295
- dispatch ( {
296
- type : UPDATE_CHILDREN_SORT ,
297
- payload : { newSortValues }
298
- } ) ;
299
- } ;
275
+ //Action reserved for SortChildren component not written yet
276
+ // export const updateChildrenSort = ({ newSortValues }: { newSortValues: any }) => (
277
+ // dispatch: (arg: Action) => void,
278
+ // ) => {
279
+ // dispatch({
280
+ // type: UPDATE_CHILDREN_SORT,
281
+ // payload: { newSortValues },
282
+ // });
283
+ // };
0 commit comments