-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Add types to legacy Redux modules
In this patch we're adopting the changes in #1855 and updating legacy reducers, action types, and action creators. This serves both as a guide for adding new Redux pieces while improving the overall type-safety and completeness of the Redux subsystem in the app.
- Loading branch information
Showing
13 changed files
with
174 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import * as auth from './auth/actions'; | ||
import * as settings from './settings/actions'; | ||
import * as ui from './ui/actions'; | ||
|
||
export default { | ||
auth, | ||
settings, | ||
ui, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
import { AUTH_SET } from '../action-types'; | ||
import * as A from '../action-types'; | ||
|
||
import { | ||
Authorized, | ||
Authorizing, | ||
InvalidCredentials, | ||
LoginError, | ||
NotAuthorized, | ||
} from './constants'; | ||
|
||
export const reset = () => ({ | ||
type: AUTH_SET, | ||
status: NotAuthorized, | ||
export const reset: A.ActionCreator<A.SetAuth> = () => ({ | ||
type: 'AUTH_SET', | ||
status: 'not-authorized', | ||
}); | ||
|
||
export const setInvalidCredentials = () => ({ | ||
type: AUTH_SET, | ||
status: InvalidCredentials, | ||
export const setInvalidCredentials: A.ActionCreator<A.SetAuth> = () => ({ | ||
type: 'AUTH_SET', | ||
status: 'invalid-credentials', | ||
}); | ||
|
||
export const setLoginError = () => ({ | ||
type: AUTH_SET, | ||
status: LoginError, | ||
export const setLoginError: A.ActionCreator<A.SetAuth> = () => ({ | ||
type: 'AUTH_SET', | ||
status: 'login-error', | ||
}); | ||
|
||
export const setPending = () => ({ | ||
type: AUTH_SET, | ||
status: Authorizing, | ||
export const setPending: A.ActionCreator<A.SetAuth> = () => ({ | ||
type: 'AUTH_SET', | ||
status: 'authorizing', | ||
}); | ||
|
||
export const setAuthorized = () => ({ | ||
type: AUTH_SET, | ||
status: Authorized, | ||
export const setAuthorized: A.ActionCreator<A.SetAuth> = () => ({ | ||
type: 'AUTH_SET', | ||
status: 'authorized', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const Authorized = Symbol(); | ||
export const Authorizing = Symbol(); | ||
export const InvalidCredentials = Symbol(); | ||
export const LoginError = Symbol(); | ||
export const NotAuthorized = Symbol(); | ||
export type AuthState = | ||
| 'authorized' | ||
| 'authorizing' | ||
| 'invalid-credentials' | ||
| 'login-error' | ||
| 'not-authorized'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import { get } from 'lodash'; | ||
import * as S from '../'; | ||
|
||
import { | ||
Authorized, | ||
Authorizing, | ||
InvalidCredentials, | ||
LoginError, | ||
} from './constants'; | ||
export const authIsPending = (state: S.State) => | ||
'authorizing' === state.auth.authStatus; | ||
|
||
export const authIsPending = state => | ||
Authorizing === get(state, 'auth.authStatus'); | ||
export const hasInvalidCredentials = (state: S.State) => | ||
'invalid-credentials' === state.auth.authStatus; | ||
|
||
export const hasInvalidCredentials = state => | ||
InvalidCredentials === get(state, 'auth.authStatus'); | ||
export const hasLoginError = (state: S.State) => | ||
'login-error' === state.auth.authStatus; | ||
|
||
export const hasLoginError = state => | ||
LoginError === get(state, 'auth.authStatus'); | ||
|
||
export const isAuthorized = state => | ||
Authorized === get(state, 'auth.authStatus'); | ||
export const isAuthorized = (state: S.State) => | ||
'authorized' === state.auth.authStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { FILTER_NOTES, TAG_DRAWER_TOGGLE } from '../action-types'; | ||
|
||
import * as A from '../action-types'; | ||
import * as T from '../../types'; | ||
|
||
export const filterNotes = (notes: T.NoteEntity[]) => ({ | ||
type: FILTER_NOTES, | ||
export const filterNotes: A.ActionCreator<A.FilterNotes> = ( | ||
notes: T.NoteEntity[] | ||
) => ({ | ||
type: 'FILTER_NOTES', | ||
notes, | ||
}); | ||
|
||
export const toggleTagDrawer = (show: boolean) => ({ | ||
type: TAG_DRAWER_TOGGLE, | ||
export const toggleTagDrawer: A.ActionCreator<A.ToggleTagDrawer> = ( | ||
show: boolean | ||
) => ({ | ||
type: 'TAG_DRAWER_TOGGLE', | ||
show, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.