1
- import { ThunkAction as ReduxThunkAction , AnyAction } from '@reduxjs/toolkit' ;
1
+ import { AnyAction , ThunkAction as ReduxThunkAction } from '@reduxjs/toolkit' ;
2
2
3
+ import { addCrateType , editCode } from './reducers/code' ;
3
4
import {
4
- getCrateType ,
5
- runAsTest ,
6
- wasmLikelyToWork ,
7
- } from './selectors' ;
5
+ changeBacktrace ,
6
+ changeChannel ,
7
+ changeEditionRaw ,
8
+ changeMode ,
9
+ changePrimaryAction ,
10
+ } from './reducers/configuration' ;
11
+ import { performCompileToAssemblyOnly } from './reducers/output/assembly' ;
12
+ import { performCommonExecute } from './reducers/output/execute' ;
13
+ import { performGistLoad } from './reducers/output/gist' ;
14
+ import { performCompileToHirOnly } from './reducers/output/hir' ;
15
+ import { performCompileToLlvmIrOnly } from './reducers/output/llvmIr' ;
16
+ import { performCompileToMirOnly } from './reducers/output/mir' ;
17
+ import { performCompileToWasmOnly } from './reducers/output/wasm' ;
18
+ import { navigateToHelp , navigateToIndex } from './reducers/page' ;
19
+ import { getCrateType , runAsTest , wasmLikelyToWork } from './selectors' ;
8
20
import State from './state' ;
9
21
import {
10
22
Backtrace ,
@@ -14,47 +26,20 @@ import {
14
26
PrimaryAction ,
15
27
PrimaryActionAuto ,
16
28
PrimaryActionCore ,
29
+ parseChannel ,
30
+ parseEdition ,
31
+ parseMode ,
17
32
} from './types' ;
18
33
19
- import { performCommonExecute , wsExecuteRequest } from './reducers/output/execute' ;
20
- import { performGistLoad } from './reducers/output/gist' ;
21
- import { performCompileToAssemblyOnly } from './reducers/output/assembly' ;
22
- import { performCompileToHirOnly } from './reducers/output/hir' ;
23
- import { performCompileToLlvmIrOnly } from './reducers/output/llvmIr' ;
24
- import { performCompileToMirOnly } from './reducers/output/mir' ;
25
- import { performCompileToWasmOnly } from './reducers/output/wasm' ;
26
- import { navigateToHelp , navigateToIndex } from './reducers/page' ;
27
- import { addCrateType , editCode } from './reducers/code' ;
28
- import {
29
- changeBacktrace ,
30
- changeChannel ,
31
- changeEditionRaw ,
32
- changeMode ,
33
- changePrimaryAction ,
34
- } from './reducers/configuration' ;
35
-
36
- export type ThunkAction < T = void > = ReduxThunkAction < T , State , { } , Action > ;
37
- export type SimpleThunkAction < T = void > = ReduxThunkAction < T , State , { } , AnyAction > ;
38
-
39
- const createAction = < T extends string , P extends { } > ( type : T , props ?: P ) => (
40
- Object . assign ( { type } , props )
41
- ) ;
42
-
43
- export enum ActionType {
44
- InitializeApplication = 'INITIALIZE_APPLICATION' ,
45
- }
46
-
47
- export const initializeApplication = ( ) => createAction ( ActionType . InitializeApplication ) ;
34
+ export type ThunkAction < T = void > = ReduxThunkAction < T , State , { } , AnyAction > ;
48
35
49
-
50
- export const reExecuteWithBacktrace = ( ) : ThunkAction => dispatch => {
36
+ export const reExecuteWithBacktrace = ( ) : ThunkAction => ( dispatch ) => {
51
37
dispatch ( changeBacktrace ( Backtrace . Enabled ) ) ;
52
38
dispatch ( performExecuteOnly ( ) ) ;
53
39
} ;
54
40
55
-
56
41
function performAutoOnly ( ) : ThunkAction {
57
- return function ( dispatch , getState ) {
42
+ return function ( dispatch , getState ) {
58
43
const state = getState ( ) ;
59
44
const crateType = getCrateType ( state ) ;
60
45
const tests = runAsTest ( state ) ;
@@ -71,7 +56,7 @@ const performTestOnly = (): ThunkAction => (dispatch, getState) => {
71
56
return dispatch ( performCommonExecute ( crateType , true ) ) ;
72
57
} ;
73
58
74
- const performCompileToNightlyHirOnly = ( ) : ThunkAction => dispatch => {
59
+ const performCompileToNightlyHirOnly = ( ) : ThunkAction => ( dispatch ) => {
75
60
dispatch ( changeChannel ( Channel . Nightly ) ) ;
76
61
dispatch ( performCompileToHirOnly ( ) ) ;
77
62
} ;
@@ -103,75 +88,56 @@ export const performPrimaryAction = (): ThunkAction => (dispatch, getState) => {
103
88
dispatch ( primaryAction ( ) ) ;
104
89
} ;
105
90
106
- const performAndSwitchPrimaryAction = ( inner : ( ) => ThunkAction , id : PrimaryAction ) => ( ) : ThunkAction => dispatch => {
107
- dispatch ( changePrimaryAction ( id ) ) ;
108
- dispatch ( inner ( ) ) ;
109
- } ;
110
-
111
- export const performExecute =
112
- performAndSwitchPrimaryAction ( performExecuteOnly , PrimaryActionCore . Execute ) ;
113
- export const performCompile =
114
- performAndSwitchPrimaryAction ( performCompileOnly , PrimaryActionCore . Compile ) ;
115
- export const performTest =
116
- performAndSwitchPrimaryAction ( performTestOnly , PrimaryActionCore . Test ) ;
117
- export const performCompileToAssembly =
118
- performAndSwitchPrimaryAction ( performCompileToAssemblyOnly , PrimaryActionCore . Asm ) ;
119
- export const performCompileToLLVM =
120
- performAndSwitchPrimaryAction ( performCompileToLlvmIrOnly , PrimaryActionCore . LlvmIr ) ;
121
- export const performCompileToMir =
122
- performAndSwitchPrimaryAction ( performCompileToMirOnly , PrimaryActionCore . Mir ) ;
123
- export const performCompileToNightlyHir =
124
- performAndSwitchPrimaryAction ( performCompileToNightlyHirOnly , PrimaryActionCore . Hir ) ;
125
- export const performCompileToWasm =
126
- performAndSwitchPrimaryAction ( performCompileToCdylibWasmOnly , PrimaryActionCore . Wasm ) ;
127
-
128
- function parseChannel ( s ?: string ) : Channel | null {
129
- switch ( s ) {
130
- case 'stable' :
131
- return Channel . Stable ;
132
- case 'beta' :
133
- return Channel . Beta ;
134
- case 'nightly' :
135
- return Channel . Nightly ;
136
- default :
137
- return null ;
138
- }
139
- }
140
-
141
- function parseMode ( s ?: string ) : Mode | null {
142
- switch ( s ) {
143
- case 'debug' :
144
- return Mode . Debug ;
145
- case 'release' :
146
- return Mode . Release ;
147
- default :
148
- return null ;
149
- }
150
- }
91
+ const performAndSwitchPrimaryAction =
92
+ ( inner : ( ) => ThunkAction , id : PrimaryAction ) => ( ) : ThunkAction => ( dispatch ) => {
93
+ dispatch ( changePrimaryAction ( id ) ) ;
94
+ dispatch ( inner ( ) ) ;
95
+ } ;
151
96
152
- function parseEdition ( s ?: string ) : Edition | null {
153
- switch ( s ) {
154
- case '2015' :
155
- return Edition . Rust2015 ;
156
- case '2018' :
157
- return Edition . Rust2018 ;
158
- case '2021' :
159
- return Edition . Rust2021 ;
160
- case '2024' :
161
- return Edition . Rust2024 ;
162
- default :
163
- return null ;
164
- }
165
- }
97
+ export const performExecute = performAndSwitchPrimaryAction (
98
+ performExecuteOnly ,
99
+ PrimaryActionCore . Execute ,
100
+ ) ;
101
+ export const performCompile = performAndSwitchPrimaryAction (
102
+ performCompileOnly ,
103
+ PrimaryActionCore . Compile ,
104
+ ) ;
105
+ export const performTest = performAndSwitchPrimaryAction ( performTestOnly , PrimaryActionCore . Test ) ;
106
+ export const performCompileToAssembly = performAndSwitchPrimaryAction (
107
+ performCompileToAssemblyOnly ,
108
+ PrimaryActionCore . Asm ,
109
+ ) ;
110
+ export const performCompileToLLVM = performAndSwitchPrimaryAction (
111
+ performCompileToLlvmIrOnly ,
112
+ PrimaryActionCore . LlvmIr ,
113
+ ) ;
114
+ export const performCompileToMir = performAndSwitchPrimaryAction (
115
+ performCompileToMirOnly ,
116
+ PrimaryActionCore . Mir ,
117
+ ) ;
118
+ export const performCompileToNightlyHir = performAndSwitchPrimaryAction (
119
+ performCompileToNightlyHirOnly ,
120
+ PrimaryActionCore . Hir ,
121
+ ) ;
122
+ export const performCompileToWasm = performAndSwitchPrimaryAction (
123
+ performCompileToCdylibWasmOnly ,
124
+ PrimaryActionCore . Wasm ,
125
+ ) ;
166
126
167
127
export function indexPageLoad ( {
168
128
code,
169
129
gist,
170
130
version,
171
131
mode : modeString ,
172
132
edition : editionString ,
173
- } : { code ?: string , gist ?: string , version ?: string , mode ?: string , edition ?: string } ) : ThunkAction {
174
- return function ( dispatch ) {
133
+ } : {
134
+ code ?: string ;
135
+ gist ?: string ;
136
+ version ?: string ;
137
+ mode ?: string ;
138
+ edition ?: string ;
139
+ } ) : ThunkAction {
140
+ return function ( dispatch ) {
175
141
const channel = parseChannel ( version ) || Channel . Stable ;
176
142
const mode = parseMode ( modeString ) || Mode . Debug ;
177
143
let maybeEdition = parseEdition ( editionString ) ;
@@ -204,21 +170,8 @@ export function indexPageLoad({
204
170
export const helpPageLoad = navigateToHelp ;
205
171
206
172
export function showExample ( code : string ) : ThunkAction {
207
- return function ( dispatch ) {
173
+ return function ( dispatch ) {
208
174
dispatch ( navigateToIndex ( ) ) ;
209
175
dispatch ( editCode ( code ) ) ;
210
176
} ;
211
177
}
212
-
213
- export type Action =
214
- | ReturnType < typeof initializeApplication >
215
- | ReturnType < typeof changeBacktrace >
216
- | ReturnType < typeof changeChannel >
217
- | ReturnType < typeof changeEditionRaw >
218
- | ReturnType < typeof changeMode >
219
- | ReturnType < typeof changePrimaryAction >
220
- | ReturnType < typeof editCode >
221
- | ReturnType < typeof addCrateType >
222
- | ReturnType < typeof navigateToIndex >
223
- | ReturnType < typeof wsExecuteRequest >
224
- ;
0 commit comments