Skip to content

Commit 12b1f7c

Browse files
committed
add GetRootState function type, and refactor modules/User/actions & preferences
1 parent 48b3705 commit 12b1f7c

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

client/modules/IDE/actions/preferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
UpdatePreferencesDispatch,
77
SetPreferencesTabValue,
88
SetFontSizeValue,
9-
GetRootState,
109
SetLineNumbersValue,
1110
SetAutocloseBracketsQuotesValue,
1211
SetAutocompleteHinterValue,
@@ -20,6 +19,7 @@ import type {
2019
SetLanguageValue,
2120
SetThemeValue
2221
} from './preferences.types';
22+
import type { GetRootState } from '../../../reducers';
2323

2424
function updatePreferences(
2525
formParams: UpdatePreferencesRequestBody,

client/modules/IDE/actions/preferences.types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ActionTypes from '../../../constants';
22
import type { PreferencesState } from '../reducers/preferences';
3-
import type { RootState } from '../../../reducers';
3+
import type { GetRootState } from '../../../reducers';
44

55
// Value Definitions:
66
export type SetPreferencesTabValue = PreferencesState['tabIndex'];
@@ -112,5 +112,3 @@ export type PreferencesThunk = (
112112
dispatch: UpdatePreferencesDispatch,
113113
getState: GetRootState
114114
) => void;
115-
116-
export type GetRootState = () => RootState;

client/modules/User/actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {
2323
UserPreferences,
2424
VerifyEmailQuery
2525
} from '../../../common/types';
26-
import { RootState } from '../../reducers';
26+
import type { GetRootState, RootState } from '../../reducers';
2727

2828
export function authError(error: Error) {
2929
return {
@@ -76,7 +76,7 @@ export function validateAndLoginUser(formProps: {
7676
}) {
7777
return (
7878
dispatch: ThunkDispatch<RootState, unknown, AnyAction>,
79-
getState: () => RootState
79+
getState: GetRootState
8080
) => {
8181
const state = getState();
8282
const { previousPath } = state.ide;
@@ -115,7 +115,7 @@ export function validateAndLoginUser(formProps: {
115115
* - Create a new user
116116
*/
117117
export function validateAndSignUpUser(formValues: CreateUserRequestBody) {
118-
return (dispatch: Dispatch, getState: () => RootState) => {
118+
return (dispatch: Dispatch, getState: GetRootState) => {
119119
const state = getState();
120120
const { previousPath } = state.ide;
121121
return new Promise<void | PublicUserOrError>((resolve) => {
@@ -161,7 +161,7 @@ export function getUser() {
161161
}
162162

163163
export function validateSession() {
164-
return async (dispatch: Dispatch, getState: () => RootState) => {
164+
return async (dispatch: Dispatch, getState: GetRootState) => {
165165
try {
166166
const response = await apiClient.get('/session');
167167
const state = getState();

client/reducers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ const rootReducer = combineReducers({
3434
// Type for entire redux state
3535
export type RootState = ReturnType<typeof rootReducer>;
3636

37+
// Type for functions that get root state
38+
export type GetRootState = () => RootState;
39+
3740
// eslint-disable-next-line import/no-default-export
3841
export default rootReducer;

0 commit comments

Comments
 (0)