1
1
import fetch from 'isomorphic-fetch' ;
2
- import { ThunkAction as ReduxThunkAction } from '@reduxjs/toolkit' ;
2
+ import { ThunkAction as ReduxThunkAction , AnyAction } from '@reduxjs/toolkit' ;
3
3
import { z } from 'zod' ;
4
4
5
5
import {
6
6
codeSelector ,
7
7
clippyRequestSelector ,
8
8
getCrateType ,
9
9
runAsTest ,
10
- useWebsocketSelector ,
11
10
} from './selectors' ;
12
11
import State from './state' ;
13
12
import {
@@ -33,6 +32,7 @@ import {
33
32
Crate ,
34
33
} from './types' ;
35
34
35
+ import { ExecuteRequestBody , performCommonExecute , wsExecuteRequest } from './reducers/output/execute' ;
36
36
import { performGistLoad } from './reducers/output/gist' ;
37
37
38
38
export const routes = {
@@ -58,6 +58,7 @@ export const routes = {
58
58
} ;
59
59
60
60
export type ThunkAction < T = void > = ReduxThunkAction < T , State , { } , Action > ;
61
+ export type SimpleThunkAction < T = void > = ReduxThunkAction < T , State , { } , AnyAction > ;
61
62
62
63
const createAction = < T extends string , P extends { } > ( type : T , props ?: P ) => (
63
64
Object . assign ( { type } , props )
@@ -82,9 +83,6 @@ export enum ActionType {
82
83
ChangeEdition = 'CHANGE_EDITION' ,
83
84
ChangeBacktrace = 'CHANGE_BACKTRACE' ,
84
85
ChangeFocus = 'CHANGE_FOCUS' ,
85
- ExecuteRequest = 'EXECUTE_REQUEST' ,
86
- ExecuteSucceeded = 'EXECUTE_SUCCEEDED' ,
87
- ExecuteFailed = 'EXECUTE_FAILED' ,
88
86
CompileAssemblyRequest = 'COMPILE_ASSEMBLY_REQUEST' ,
89
87
CompileAssemblySucceeded = 'COMPILE_ASSEMBLY_SUCCEEDED' ,
90
88
CompileAssemblyFailed = 'COMPILE_ASSEMBLY_FAILED' ,
@@ -126,8 +124,6 @@ export enum ActionType {
126
124
WebSocketConnected = 'WEBSOCKET_CONNECTED' ,
127
125
WebSocketDisconnected = 'WEBSOCKET_DISCONNECTED' ,
128
126
WebSocketFeatureFlagEnabled = 'WEBSOCKET_FEATURE_FLAG_ENABLED' ,
129
- WSExecuteRequest = 'WS_EXECUTE_REQUEST' ,
130
- WSExecuteResponse = 'WS_EXECUTE_RESPONSE' ,
131
127
}
132
128
133
129
export const WebSocketError = z . object ( {
@@ -136,20 +132,6 @@ export const WebSocketError = z.object({
136
132
} ) ;
137
133
export type WebSocketError = z . infer < typeof WebSocketError > ;
138
134
139
- const ExecuteExtra = z . object ( {
140
- sequenceNumber : z . number ( ) ,
141
- } ) ;
142
- type ExecuteExtra = z . infer < typeof ExecuteExtra > ;
143
-
144
- export const WSExecuteResponse = z . object ( {
145
- type : z . literal ( ActionType . WSExecuteResponse ) ,
146
- success : z . boolean ( ) ,
147
- stdout : z . string ( ) ,
148
- stderr : z . string ( ) ,
149
- extra : ExecuteExtra ,
150
- } ) ;
151
- export type WSExecuteResponse = z . infer < typeof WSExecuteResponse > ;
152
-
153
135
export const initializeApplication = ( ) => createAction ( ActionType . InitializeApplication ) ;
154
136
155
137
export const disableSyncChangesToStorage = ( ) => createAction ( ActionType . DisableSyncChangesToStorage ) ;
@@ -210,20 +192,6 @@ export const reExecuteWithBacktrace = (): ThunkAction => dispatch => {
210
192
export const changeFocus = ( focus ?: Focus ) =>
211
193
createAction ( ActionType . ChangeFocus , { focus } ) ;
212
194
213
- interface ExecuteResponseBody {
214
- stdout : string ;
215
- stderr : string ;
216
- }
217
-
218
- const requestExecute = ( ) =>
219
- createAction ( ActionType . ExecuteRequest ) ;
220
-
221
- const receiveExecuteSuccess = ( { stdout, stderr } : ExecuteResponseBody ) =>
222
- createAction ( ActionType . ExecuteSucceeded , { stdout, stderr } ) ;
223
-
224
- const receiveExecuteFailure = ( { error } : { error ?: string } ) =>
225
- createAction ( ActionType . ExecuteFailed , { error } ) ;
226
-
227
195
type FetchArg = Parameters < typeof fetch > [ 0 ] ;
228
196
229
197
export function jsonGet ( url : FetchArg ) {
@@ -298,35 +266,6 @@ export const adaptFetchError = async <R>(cb: () => Promise<R>): Promise<R> => {
298
266
}
299
267
}
300
268
301
- interface ExecuteRequestBody {
302
- channel : string ;
303
- mode : string ;
304
- crateType : string ;
305
- tests : boolean ;
306
- code : string ;
307
- edition : string ;
308
- backtrace : boolean ;
309
- }
310
-
311
- const performCommonExecute = ( crateType : string , tests : boolean ) : ThunkAction => ( dispatch , getState ) => {
312
- const state = getState ( ) ;
313
- const code = codeSelector ( state ) ;
314
- const { configuration : { channel, mode, edition } } = state ;
315
- const backtrace = state . configuration . backtrace === Backtrace . Enabled ;
316
-
317
- if ( useWebsocketSelector ( state ) ) {
318
- return dispatch ( wsExecuteRequest ( channel , mode , edition , crateType , tests , code , backtrace ) ) ;
319
- } else {
320
- dispatch ( requestExecute ( ) ) ;
321
-
322
- const body : ExecuteRequestBody = { channel, mode, edition, crateType, tests, code, backtrace } ;
323
-
324
- return jsonPost < ExecuteResponseBody > ( routes . execute , body )
325
- . then ( json => dispatch ( receiveExecuteSuccess ( json ) ) )
326
- . catch ( json => dispatch ( receiveExecuteFailure ( json ) ) ) ;
327
- }
328
- } ;
329
-
330
269
function performAutoOnly ( ) : ThunkAction {
331
270
return function ( dispatch , getState ) {
332
271
const state = getState ( ) ;
@@ -506,32 +445,6 @@ const PRIMARY_ACTIONS: { [index in PrimaryAction]: () => ThunkAction } = {
506
445
[ PrimaryActionCore . Wasm ] : performCompileToNightlyWasmOnly ,
507
446
} ;
508
447
509
- let sequenceNumber = 0 ;
510
- const nextSequenceNumber = ( ) => sequenceNumber ++ ;
511
- const makeExtra = ( ) : ExecuteExtra => ( {
512
- sequenceNumber : nextSequenceNumber ( ) ,
513
- } ) ;
514
-
515
- const wsExecuteRequest = (
516
- channel : Channel ,
517
- mode : Mode ,
518
- edition : Edition ,
519
- crateType : string ,
520
- tests : boolean ,
521
- code : string ,
522
- backtrace : boolean
523
- ) =>
524
- createAction ( ActionType . WSExecuteRequest , {
525
- channel,
526
- mode,
527
- edition,
528
- crateType,
529
- tests,
530
- code,
531
- backtrace,
532
- extra : makeExtra ( ) ,
533
- } ) ;
534
-
535
448
export const performPrimaryAction = ( ) : ThunkAction => ( dispatch , getState ) => {
536
449
const state = getState ( ) ;
537
450
const primaryAction = PRIMARY_ACTIONS [ state . configuration . primaryAction ] ;
@@ -871,9 +784,6 @@ export type Action =
871
784
| ReturnType < typeof changeProcessAssembly >
872
785
| ReturnType < typeof changeAceTheme >
873
786
| ReturnType < typeof changeMonacoTheme >
874
- | ReturnType < typeof requestExecute >
875
- | ReturnType < typeof receiveExecuteSuccess >
876
- | ReturnType < typeof receiveExecuteFailure >
877
787
| ReturnType < typeof requestCompileAssembly >
878
788
| ReturnType < typeof receiveCompileAssemblySuccess >
879
789
| ReturnType < typeof receiveCompileAssemblyFailure >
@@ -916,5 +826,4 @@ export type Action =
916
826
| ReturnType < typeof websocketDisconnected >
917
827
| ReturnType < typeof websocketFeatureFlagEnabled >
918
828
| ReturnType < typeof wsExecuteRequest >
919
- | WSExecuteResponse
920
829
;
0 commit comments