@@ -4,7 +4,7 @@ import { dispatch as coreDispatch } from '@wordpress/data';
4
4
import { store as editorStore } from '@wordpress/editor' ;
5
5
import { __ , sprintf } from '@wordpress/i18n' ;
6
6
import { getSocialScriptData } from '../../utils/script-data' ;
7
- import { Connection } from '../types' ;
7
+ import { Connection , KeyringResult } from '../types' ;
8
8
import {
9
9
ADD_CONNECTION ,
10
10
DELETE_CONNECTION ,
@@ -23,10 +23,10 @@ import {
23
23
24
24
/**
25
25
* Set connections list
26
- * @param { Array<import('../types').Connection> } connections - list of connections
27
- * @return { object } - an action object.
26
+ * @param connections - list of connections
27
+ * @return An action object.
28
28
*/
29
- export function setConnections ( connections ) {
29
+ export function setConnections ( connections : Array < Connection > ) {
30
30
return {
31
31
type : SET_CONNECTIONS ,
32
32
connections,
@@ -36,11 +36,11 @@ export function setConnections( connections ) {
36
36
/**
37
37
* Set keyring result
38
38
*
39
- * @param { import('../types').KeyringResult } [ keyringResult] - keyring result
39
+ * @param keyringResult - keyring result
40
40
*
41
- * @return { object } - an action object.
41
+ * @return An action object.
42
42
*/
43
- export function setKeyringResult ( keyringResult ) {
43
+ export function setKeyringResult ( keyringResult ?: KeyringResult ) {
44
44
return {
45
45
type : SET_KEYRING_RESULT ,
46
46
keyringResult,
@@ -49,10 +49,10 @@ export function setKeyringResult( keyringResult ) {
49
49
50
50
/**
51
51
* Add connection to the list
52
- * @param { import('../types').Connection } connection - connection object
53
- * @return { object } - an action object.
52
+ * @param connection - connection object
53
+ * @return An action object.
54
54
*/
55
- export function addConnection ( connection ) {
55
+ export function addConnection ( connection : Partial < Connection > ) {
56
56
return {
57
57
type : ADD_CONNECTION ,
58
58
connection,
@@ -61,11 +61,11 @@ export function addConnection( connection ) {
61
61
62
62
/**
63
63
* Toggle connection enable status.
64
- * @param { string } connectionId - Connection ID to switch.
64
+ * @param connectionId - Connection ID to switch.
65
65
*
66
- * @return { object } Switch connection enable-status action.
66
+ * @return Switch connection enable-status action.
67
67
*/
68
- export function toggleConnection ( connectionId ) {
68
+ export function toggleConnection ( connectionId : string ) {
69
69
return {
70
70
type : TOGGLE_CONNECTION ,
71
71
connectionId,
@@ -74,13 +74,13 @@ export function toggleConnection( connectionId ) {
74
74
75
75
/**
76
76
* Merge connections with fresh connections.
77
- * @param { Array } freshConnections - list of fresh connections
78
- * @return { Function } - a function to merge connections.
77
+ * @param freshConnections - list of fresh connections
78
+ * @return A thunk to merge connections.
79
79
*/
80
- export function mergeConnections ( freshConnections ) {
80
+ export function mergeConnections ( freshConnections : Array < Connection > ) {
81
81
return function ( { dispatch, select } ) {
82
82
// Combine current connections with new connections.
83
- const prevConnections = select . getConnections ( ) ;
83
+ const prevConnections : Array < Connection > = select . getConnections ( ) ;
84
84
const connections = [ ] ;
85
85
const defaults = {
86
86
enabled : true ,
@@ -108,12 +108,12 @@ export function mergeConnections( freshConnections ) {
108
108
109
109
/**
110
110
* Create an abort controller.
111
- * @param { AbortController } abortController - Abort controller.
112
- * @param { string } requestType - Type of abort request.
111
+ * @param abortController - Abort controller.
112
+ * @param requestType - Type of abort request.
113
113
*
114
- * @return { object } - an action object.
114
+ * @return An action object.
115
115
*/
116
- export function createAbortController ( abortController , requestType ) {
116
+ export function createAbortController ( abortController : AbortController , requestType : string ) {
117
117
return {
118
118
type : ADD_ABORT_CONTROLLER ,
119
119
requestType,
@@ -124,11 +124,11 @@ export function createAbortController( abortController, requestType ) {
124
124
/**
125
125
* Remove abort controllers.
126
126
*
127
- * @param { string } requestType - Type of abort request.
127
+ * @param requestType - Type of abort request.
128
128
*
129
- * @return { object } - an action object.
129
+ * @return An action object.
130
130
*/
131
- export function removeAbortControllers ( requestType ) {
131
+ export function removeAbortControllers ( requestType : string ) {
132
132
return {
133
133
type : REMOVE_ABORT_CONTROLLERS ,
134
134
requestType,
@@ -138,11 +138,11 @@ export function removeAbortControllers( requestType ) {
138
138
/**
139
139
* Abort a request.
140
140
*
141
- * @param { string } requestType - Type of abort request.
141
+ * @param requestType - Type of abort request.
142
142
*
143
- * @return { Function } - a function to abort a request.
143
+ * @return A thunk to abort a request.
144
144
*/
145
- export function abortRequest ( requestType ) {
145
+ export function abortRequest ( requestType : string ) {
146
146
return function ( { dispatch, select } ) {
147
147
const abortControllers = select . getAbortControllers ( requestType ) ;
148
148
@@ -158,7 +158,7 @@ export function abortRequest( requestType ) {
158
158
/**
159
159
* Abort the refresh connections request.
160
160
*
161
- * @return { Function } - a function to abort a request.
161
+ * @return A thunk to abort a request.
162
162
*/
163
163
export function abortRefreshConnectionsRequest ( ) {
164
164
return abortRequest ( REQUEST_TYPE_REFRESH_CONNECTIONS ) ;
@@ -167,8 +167,8 @@ export function abortRefreshConnectionsRequest() {
167
167
/**
168
168
* Effect handler which will refresh the connection test results.
169
169
*
170
- * @param { boolean } syncToMeta - Whether to sync the connection state to the post meta.
171
- * @return { Function } Refresh connection test results action .
170
+ * @param syncToMeta - Whether to sync the connection state to the post meta.
171
+ * @return A thunk to refresh connection test results.
172
172
*/
173
173
export function refreshConnectionTestResults ( syncToMeta = false ) {
174
174
return async function ( { dispatch, select } ) {
@@ -188,7 +188,10 @@ export function refreshConnectionTestResults( syncToMeta = false ) {
188
188
dispatch ( createAbortController ( abortController , REQUEST_TYPE_REFRESH_CONNECTIONS ) ) ;
189
189
190
190
// Pass the abort controller signal to the fetch request.
191
- const freshConnections = await apiFetch ( { path, signal : abortController . signal } ) ;
191
+ const freshConnections = await apiFetch < Array < Connection > > ( {
192
+ path,
193
+ signal : abortController . signal ,
194
+ } ) ;
192
195
193
196
dispatch ( mergeConnections ( freshConnections ) ) ;
194
197
@@ -208,7 +211,7 @@ export function refreshConnectionTestResults( syncToMeta = false ) {
208
211
/**
209
212
* Syncs the connections to the post meta.
210
213
*
211
- * @return { Function } Sync connections to post meta action .
214
+ * @return A thunk to sync connections to post meta.
212
215
*/
213
216
export function syncConnectionsToPostMeta ( ) {
214
217
return function ( { registry, select } ) {
@@ -224,11 +227,11 @@ export function syncConnectionsToPostMeta() {
224
227
/**
225
228
* Toggles the connection enable-status.
226
229
*
227
- * @param { string } connectionId - Connection ID to switch.
228
- * @param { boolean } syncToMeta - Whether to sync the connection state to the post meta.
229
- * @return { object } Switch connection enable-status action .
230
+ * @param connectionId - Connection ID to switch.
231
+ * @param syncToMeta - Whether to sync the connection state to the post meta.
232
+ * @return A think to switch connection enable-status.
230
233
*/
231
- export function toggleConnectionById ( connectionId , syncToMeta = true ) {
234
+ export function toggleConnectionById ( connectionId : string , syncToMeta = true ) {
232
235
return function ( { dispatch } ) {
233
236
dispatch ( toggleConnection ( connectionId ) ) ;
234
237
@@ -241,11 +244,11 @@ export function toggleConnectionById( connectionId, syncToMeta = true ) {
241
244
/**
242
245
* Deletes a connection.
243
246
*
244
- * @param { string } connectionId - Connection ID to delete.
247
+ * @param connectionId - Connection ID to delete.
245
248
*
246
- * @return { object } Delete connection action.
249
+ * @return An action object .
247
250
*/
248
- export function deleteConnection ( connectionId ) {
251
+ export function deleteConnection ( connectionId : string ) {
249
252
return {
250
253
type : DELETE_CONNECTION ,
251
254
connectionId,
@@ -255,12 +258,12 @@ export function deleteConnection( connectionId ) {
255
258
/**
256
259
* Marks a connection as being deleted.
257
260
*
258
- * @param { string } connectionId - Connection ID to delete.
259
- * @param { boolean } deleting - Whether the connection is being deleted.
261
+ * @param connectionId - Connection ID to delete.
262
+ * @param deleting - Whether the connection is being deleted.
260
263
*
261
- * @return { object } Deleting connection action.
264
+ * @return An action object .
262
265
*/
263
- export function deletingConnection ( connectionId , deleting = true ) {
266
+ export function deletingConnection ( connectionId : string , deleting = true ) {
264
267
return {
265
268
type : DELETING_CONNECTION ,
266
269
connectionId,
@@ -271,13 +274,19 @@ export function deletingConnection( connectionId, deleting = true ) {
271
274
/**
272
275
* Deletes a connection by disconnecting it.
273
276
*
274
- * @param { object } args - Arguments.
275
- * @param { string | number } args.connectionId - Connection ID to delete.
276
- * @param { boolean } [ args.showSuccessNotice] - Whether to show a success notice.
277
+ * @param args - Arguments.
278
+ * @param args.connectionId - Connection ID to delete.
279
+ * @param args.showSuccessNotice - Whether to show a success notice.
277
280
*
278
- * @return { boolean } Whether the connection was deleted.
281
+ * @return A thunk that resolves to true if the connection was deleted, false otherwise .
279
282
*/
280
- export function deleteConnectionById ( { connectionId, showSuccessNotice = true } ) {
283
+ export function deleteConnectionById ( {
284
+ connectionId,
285
+ showSuccessNotice = true ,
286
+ } : {
287
+ connectionId : string ;
288
+ showSuccessNotice ?: boolean ;
289
+ } ) {
281
290
return async function ( { registry, dispatch } ) {
282
291
const { createErrorNotice, createSuccessNotice } = coreDispatch ( globalNoticesStore ) ;
283
292
@@ -330,11 +339,15 @@ let uniqueId = 1;
330
339
/**
331
340
* Creates a connection.
332
341
*
333
- * @param {Record<string, any> } data - The data for API call.
334
- * @param {Record<string, any> } optimisticData - Optimistic data for the connection.
335
- * @return {void }
342
+ * @param data - The data for API call.
343
+ * @param optimisticData - Optimistic data for the connection.
344
+ *
345
+ * @return A thunk to create a connection.
336
346
*/
337
- export function createConnection ( data , optimisticData = { } ) {
347
+ export function createConnection (
348
+ data : Record < string , unknown > ,
349
+ optimisticData : Partial < Connection > = { }
350
+ ) {
338
351
return async function ( { registry, dispatch } ) {
339
352
const { createErrorNotice, createSuccessNotice } = coreDispatch ( globalNoticesStore ) ;
340
353
@@ -403,12 +416,12 @@ export function createConnection( data, optimisticData = {} ) {
403
416
/**
404
417
* Updates a connection.
405
418
*
406
- * @param { string } connectionId - Connection ID to update.
407
- * @param { Record<string, any> } data - The data.
419
+ * @param connectionId - Connection ID to update.
420
+ * @param data - The data.
408
421
*
409
- * @return { object } Delete connection action.
422
+ * @return An action object .
410
423
*/
411
- export function updateConnection ( connectionId , data ) {
424
+ export function updateConnection ( connectionId : string , data : Partial < Connection > ) {
412
425
return {
413
426
type : UPDATE_CONNECTION ,
414
427
connectionId,
@@ -419,12 +432,12 @@ export function updateConnection( connectionId, data ) {
419
432
/**
420
433
* Marks a connection as being updating.
421
434
*
422
- * @param { string } connectionId - Connection ID being updated.
423
- * @param { boolean } updating - Whether the connection is being updated.
435
+ * @param connectionId - Connection ID being updated.
436
+ * @param updating - Whether the connection is being updated.
424
437
*
425
- * @return { object } Deleting connection action.
438
+ * @return An action object .
426
439
*/
427
- export function updatingConnection ( connectionId , updating = true ) {
440
+ export function updatingConnection ( connectionId : string , updating = true ) {
428
441
return {
429
442
type : UPDATING_CONNECTION ,
430
443
connectionId,
@@ -435,11 +448,11 @@ export function updatingConnection( connectionId, updating = true ) {
435
448
/**
436
449
* Sets the reconnecting account.
437
450
*
438
- * @param { import('../types').Connection } reconnectingAccount - Account being reconnected.
451
+ * @param reconnectingAccount - Account being reconnected.
439
452
*
440
- * @return { object } Reconnecting account action.
453
+ * @return An action object .
441
454
*/
442
- export function setReconnectingAccount ( reconnectingAccount ) {
455
+ export function setReconnectingAccount ( reconnectingAccount : Connection ) {
443
456
return {
444
457
type : SET_RECONNECTING_ACCOUNT ,
445
458
reconnectingAccount,
@@ -449,11 +462,11 @@ export function setReconnectingAccount( reconnectingAccount ) {
449
462
/**
450
463
* Updates a connection.
451
464
*
452
- * @param { string } connectionId - Connection ID to update.
453
- * @param { Record<string, any> } data - The data for API call.
454
- * @return { void }
465
+ * @param connectionId - Connection ID to update.
466
+ * @param data - The data for API call.
467
+ * @return A thunk to update a connection.
455
468
*/
456
- export function updateConnectionById ( connectionId , data ) {
469
+ export function updateConnectionById ( connectionId : string , data : Partial < Connection > ) {
457
470
return async function ( { dispatch, select } ) {
458
471
const { createErrorNotice, createSuccessNotice } = coreDispatch ( globalNoticesStore ) ;
459
472
@@ -501,11 +514,11 @@ export function updateConnectionById( connectionId, data ) {
501
514
/**
502
515
* Toggles the connections modal.
503
516
*
504
- * @param { boolean } isOpen - Whether the modal is open.
517
+ * @param isOpen - Whether the modal is open.
505
518
*
506
- * @return { object } - An action object.
519
+ * @return An action object.
507
520
*/
508
- export function toggleConnectionsModal ( isOpen ) {
521
+ export function toggleConnectionsModal ( isOpen : boolean ) {
509
522
return {
510
523
type : TOGGLE_CONNECTIONS_MODAL ,
511
524
isOpen,
@@ -515,15 +528,15 @@ export function toggleConnectionsModal( isOpen ) {
515
528
/**
516
529
* Opens the connections modal.
517
530
*
518
- * @return { object } - An action object.
531
+ * @return An action object.
519
532
*/
520
533
export function openConnectionsModal ( ) {
521
534
return toggleConnectionsModal ( true ) ;
522
535
}
523
536
524
537
/**
525
538
* Closes the connections modal.
526
- * @return { object } - An action object.
539
+ * @return An action object.
527
540
*/
528
541
export function closeConnectionsModal ( ) {
529
542
return toggleConnectionsModal ( false ) ;
0 commit comments