1- import { ThunkAction as ReduxThunkAction , AnyAction } from '@reduxjs/toolkit' ;
1+ import { AnyAction , ThunkAction as ReduxThunkAction } from '@reduxjs/toolkit' ;
22
3+ import { addCrateType , editCode } from './reducers/code' ;
34import {
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' ;
820import State from './state' ;
921import {
1022 Backtrace ,
@@ -14,47 +26,20 @@ import {
1426 PrimaryAction ,
1527 PrimaryActionAuto ,
1628 PrimaryActionCore ,
29+ parseChannel ,
30+ parseEdition ,
31+ parseMode ,
1732} from './types' ;
1833
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 > ;
4835
49-
50- export const reExecuteWithBacktrace = ( ) : ThunkAction => dispatch => {
36+ export const reExecuteWithBacktrace = ( ) : ThunkAction => ( dispatch ) => {
5137 dispatch ( changeBacktrace ( Backtrace . Enabled ) ) ;
5238 dispatch ( performExecuteOnly ( ) ) ;
5339} ;
5440
55-
5641function performAutoOnly ( ) : ThunkAction {
57- return function ( dispatch , getState ) {
42+ return function ( dispatch , getState ) {
5843 const state = getState ( ) ;
5944 const crateType = getCrateType ( state ) ;
6045 const tests = runAsTest ( state ) ;
@@ -71,7 +56,7 @@ const performTestOnly = (): ThunkAction => (dispatch, getState) => {
7156 return dispatch ( performCommonExecute ( crateType , true ) ) ;
7257} ;
7358
74- const performCompileToNightlyHirOnly = ( ) : ThunkAction => dispatch => {
59+ const performCompileToNightlyHirOnly = ( ) : ThunkAction => ( dispatch ) => {
7560 dispatch ( changeChannel ( Channel . Nightly ) ) ;
7661 dispatch ( performCompileToHirOnly ( ) ) ;
7762} ;
@@ -103,75 +88,56 @@ export const performPrimaryAction = (): ThunkAction => (dispatch, getState) => {
10388 dispatch ( primaryAction ( ) ) ;
10489} ;
10590
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+ } ;
15196
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+ ) ;
166126
167127export function indexPageLoad ( {
168128 code,
169129 gist,
170130 version,
171131 mode : modeString ,
172132 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 ) {
175141 const channel = parseChannel ( version ) || Channel . Stable ;
176142 const mode = parseMode ( modeString ) || Mode . Debug ;
177143 let maybeEdition = parseEdition ( editionString ) ;
@@ -204,21 +170,8 @@ export function indexPageLoad({
204170export const helpPageLoad = navigateToHelp ;
205171
206172export function showExample ( code : string ) : ThunkAction {
207- return function ( dispatch ) {
173+ return function ( dispatch ) {
208174 dispatch ( navigateToIndex ( ) ) ;
209175 dispatch ( editCode ( code ) ) ;
210176 } ;
211177}
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