Skip to content

Commit 18751e3

Browse files
committed
client/modules/IDE/actions/preferences: define types for dispatcher, formParams, getState, and setter params
1 parent 80484ea commit 18751e3

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

client/modules/IDE/actions/preferences.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import i18next from 'i18next';
2+
import {
3+
UserPreferences as Preferences,
4+
AppThemeOptions,
5+
UpdatePreferencesRequestBody
6+
} from '../../../../common/types';
27
import { apiClient } from '../../../utils/apiClient';
38
import * as ActionTypes from '../../../constants';
9+
import { PreferencesState } from '../reducers/preferences';
10+
import { RootState } from '../../../reducers';
411

5-
function updatePreferences(formParams, dispatch) {
12+
export type UpdatePreferencesDispatch = (action: unknown) => void;
13+
export type GetRootState = () => RootState;
14+
15+
function updatePreferences(
16+
formParams: UpdatePreferencesRequestBody,
17+
dispatch: UpdatePreferencesDispatch
18+
) {
619
apiClient
720
.put('/preferences', formParams)
821
.then(() => {})
@@ -14,15 +27,15 @@ function updatePreferences(formParams, dispatch) {
1427
});
1528
}
1629

17-
export function setPreferencesTab(value) {
30+
export function setPreferencesTab(value: PreferencesState['tabIndex']) {
1831
return {
1932
type: ActionTypes.SET_PREFERENCES_TAB,
2033
value
2134
};
2235
}
2336

24-
export function setFontSize(value) {
25-
return (dispatch, getState) => {
37+
export function setFontSize(value: PreferencesState['fontSize']) {
38+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
2639
// eslint-disable-line
2740
dispatch({
2841
type: ActionTypes.SET_FONT_SIZE,
@@ -41,7 +54,7 @@ export function setFontSize(value) {
4154
}
4255

4356
export function setLineNumbers(value) {
44-
return (dispatch, getState) => {
57+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
4558
dispatch({
4659
type: ActionTypes.SET_LINE_NUMBERS,
4760
value
@@ -59,7 +72,7 @@ export function setLineNumbers(value) {
5972
}
6073

6174
export function setAutocloseBracketsQuotes(value) {
62-
return (dispatch, getState) => {
75+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
6376
dispatch({
6477
type: ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES,
6578
value
@@ -77,7 +90,7 @@ export function setAutocloseBracketsQuotes(value) {
7790
}
7891

7992
export function setAutocompleteHinter(value) {
80-
return (dispatch, getState) => {
93+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
8194
dispatch({
8295
type: ActionTypes.SET_AUTOCOMPLETE_HINTER,
8396
value
@@ -95,7 +108,7 @@ export function setAutocompleteHinter(value) {
95108
}
96109

97110
export function setAutosave(value) {
98-
return (dispatch, getState) => {
111+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
99112
dispatch({
100113
type: ActionTypes.SET_AUTOSAVE,
101114
value
@@ -113,7 +126,7 @@ export function setAutosave(value) {
113126
}
114127

115128
export function setLinewrap(value) {
116-
return (dispatch, getState) => {
129+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
117130
dispatch({
118131
type: ActionTypes.SET_LINEWRAP,
119132
value
@@ -131,7 +144,7 @@ export function setLinewrap(value) {
131144
}
132145

133146
export function setLintWarning(value) {
134-
return (dispatch, getState) => {
147+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
135148
dispatch({
136149
type: ActionTypes.SET_LINT_WARNING,
137150
value
@@ -149,7 +162,7 @@ export function setLintWarning(value) {
149162
}
150163

151164
export function setTextOutput(value) {
152-
return (dispatch, getState) => {
165+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
153166
dispatch({
154167
type: ActionTypes.SET_TEXT_OUTPUT,
155168
value
@@ -167,7 +180,7 @@ export function setTextOutput(value) {
167180
}
168181

169182
export function setGridOutput(value) {
170-
return (dispatch, getState) => {
183+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
171184
dispatch({
172185
type: ActionTypes.SET_GRID_OUTPUT,
173186
value
@@ -185,11 +198,7 @@ export function setGridOutput(value) {
185198
}
186199

187200
export function setTheme(value) {
188-
// return {
189-
// type: ActionTypes.SET_THEME,
190-
// value
191-
// };
192-
return (dispatch, getState) => {
201+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
193202
dispatch({
194203
type: ActionTypes.SET_THEME,
195204
value
@@ -207,11 +216,7 @@ export function setTheme(value) {
207216
}
208217

209218
export function setAutorefresh(value) {
210-
// return {
211-
// type: ActionTypes.SET_AUTOREFRESH,
212-
// value
213-
// };
214-
return (dispatch, getState) => {
219+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
215220
dispatch({
216221
type: ActionTypes.SET_AUTOREFRESH,
217222
value
@@ -229,14 +234,14 @@ export function setAutorefresh(value) {
229234
}
230235

231236
export function setAllAccessibleOutput(value) {
232-
return (dispatch) => {
237+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
233238
dispatch(setTextOutput(value));
234239
dispatch(setGridOutput(value));
235240
};
236241
}
237242

238243
export function setLanguage(value, { persistPreference = true } = {}) {
239-
return (dispatch, getState) => {
244+
return (dispatch: UpdatePreferencesDispatch, getState: GetRootState) => {
240245
i18next.changeLanguage(value);
241246
dispatch({
242247
type: ActionTypes.SET_LANGUAGE,

client/modules/IDE/reducers/preferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface PreferencesState
1313
// prettier-ignore
1414
export type PreferencesAction =
1515
| { type: typeof ActionTypes.OPEN_PREFERENCES }
16-
| { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: number }
16+
| { type: typeof ActionTypes.SET_PREFERENCES_TAB; value: PreferencesState['tabIndex'] }
1717
| { type: typeof ActionTypes.SET_FONT_SIZE; value: Preferences['fontSize'] }
1818
| { type: typeof ActionTypes.SET_AUTOSAVE; value: Preferences['autosave'] }
1919
| { type: typeof ActionTypes.SET_LINEWRAP; value: Preferences['linewrap'] }

0 commit comments

Comments
 (0)