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 ,
@@ -19,33 +31,15 @@ import {
19
31
parseMode ,
20
32
} from './types' ;
21
33
22
- import { performCommonExecute } from './reducers/output/execute' ;
23
- import { performGistLoad } from './reducers/output/gist' ;
24
- import { performCompileToAssemblyOnly } from './reducers/output/assembly' ;
25
- import { performCompileToHirOnly } from './reducers/output/hir' ;
26
- import { performCompileToLlvmIrOnly } from './reducers/output/llvmIr' ;
27
- import { performCompileToMirOnly } from './reducers/output/mir' ;
28
- import { performCompileToWasmOnly } from './reducers/output/wasm' ;
29
- import { navigateToHelp , navigateToIndex } from './reducers/page' ;
30
- import { addCrateType , editCode } from './reducers/code' ;
31
- import {
32
- changeBacktrace ,
33
- changeChannel ,
34
- changeEditionRaw ,
35
- changeMode ,
36
- changePrimaryAction ,
37
- } from './reducers/configuration' ;
38
-
39
34
export type ThunkAction < T = void > = ReduxThunkAction < T , State , { } , AnyAction > ;
40
35
41
- export const reExecuteWithBacktrace = ( ) : ThunkAction => dispatch => {
36
+ export const reExecuteWithBacktrace = ( ) : ThunkAction => ( dispatch ) => {
42
37
dispatch ( changeBacktrace ( Backtrace . Enabled ) ) ;
43
38
dispatch ( performExecuteOnly ( ) ) ;
44
39
} ;
45
40
46
-
47
41
function performAutoOnly ( ) : ThunkAction {
48
- return function ( dispatch , getState ) {
42
+ return function ( dispatch , getState ) {
49
43
const state = getState ( ) ;
50
44
const crateType = getCrateType ( state ) ;
51
45
const tests = runAsTest ( state ) ;
@@ -62,7 +56,7 @@ const performTestOnly = (): ThunkAction => (dispatch, getState) => {
62
56
return dispatch ( performCommonExecute ( crateType , true ) ) ;
63
57
} ;
64
58
65
- const performCompileToNightlyHirOnly = ( ) : ThunkAction => dispatch => {
59
+ const performCompileToNightlyHirOnly = ( ) : ThunkAction => ( dispatch ) => {
66
60
dispatch ( changeChannel ( Channel . Nightly ) ) ;
67
61
dispatch ( performCompileToHirOnly ( ) ) ;
68
62
} ;
@@ -94,36 +88,56 @@ export const performPrimaryAction = (): ThunkAction => (dispatch, getState) => {
94
88
dispatch ( primaryAction ( ) ) ;
95
89
} ;
96
90
97
- const performAndSwitchPrimaryAction = ( inner : ( ) => ThunkAction , id : PrimaryAction ) => ( ) : ThunkAction => dispatch => {
98
- dispatch ( changePrimaryAction ( id ) ) ;
99
- dispatch ( inner ( ) ) ;
100
- } ;
91
+ const performAndSwitchPrimaryAction =
92
+ ( inner : ( ) => ThunkAction , id : PrimaryAction ) => ( ) : ThunkAction => ( dispatch ) => {
93
+ dispatch ( changePrimaryAction ( id ) ) ;
94
+ dispatch ( inner ( ) ) ;
95
+ } ;
101
96
102
- export const performExecute =
103
- performAndSwitchPrimaryAction ( performExecuteOnly , PrimaryActionCore . Execute ) ;
104
- export const performCompile =
105
- performAndSwitchPrimaryAction ( performCompileOnly , PrimaryActionCore . Compile ) ;
106
- export const performTest =
107
- performAndSwitchPrimaryAction ( performTestOnly , PrimaryActionCore . Test ) ;
108
- export const performCompileToAssembly =
109
- performAndSwitchPrimaryAction ( performCompileToAssemblyOnly , PrimaryActionCore . Asm ) ;
110
- export const performCompileToLLVM =
111
- performAndSwitchPrimaryAction ( performCompileToLlvmIrOnly , PrimaryActionCore . LlvmIr ) ;
112
- export const performCompileToMir =
113
- performAndSwitchPrimaryAction ( performCompileToMirOnly , PrimaryActionCore . Mir ) ;
114
- export const performCompileToNightlyHir =
115
- performAndSwitchPrimaryAction ( performCompileToNightlyHirOnly , PrimaryActionCore . Hir ) ;
116
- export const performCompileToWasm =
117
- performAndSwitchPrimaryAction ( performCompileToCdylibWasmOnly , PrimaryActionCore . Wasm ) ;
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
+ ) ;
118
126
119
127
export function indexPageLoad ( {
120
128
code,
121
129
gist,
122
130
version,
123
131
mode : modeString ,
124
132
edition : editionString ,
125
- } : { code ?: string , gist ?: string , version ?: string , mode ?: string , edition ?: string } ) : ThunkAction {
126
- 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 ) {
127
141
const channel = parseChannel ( version ) || Channel . Stable ;
128
142
const mode = parseMode ( modeString ) || Mode . Debug ;
129
143
let maybeEdition = parseEdition ( editionString ) ;
@@ -156,7 +170,7 @@ export function indexPageLoad({
156
170
export const helpPageLoad = navigateToHelp ;
157
171
158
172
export function showExample ( code : string ) : ThunkAction {
159
- return function ( dispatch ) {
173
+ return function ( dispatch ) {
160
174
dispatch ( navigateToIndex ( ) ) ;
161
175
dispatch ( editCode ( code ) ) ;
162
176
} ;
0 commit comments