This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because I had to install a beta version of redux in order to get it to stop throwing dispatch type errors, based on advice from some issue, I had a subsequent problem with redux-thunk not yet supporting that new version. There was a pull request already though to fix this, so I pulled the changes from [that pr] into my redux-thunk npm package to get it to work. I have a comment on that PR as to exactly what I did. As of this moment though, that PR still isn't quite finished and thus this does not compile. [that pr]: reduxjs/redux-thunk#180
- Loading branch information
Showing
11 changed files
with
96 additions
and
71 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
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,31 +1,38 @@ | ||
import { createAction } from 'typesafe-actions' | ||
import {Action, ActionCreator, Dispatch} from 'redux' | ||
import {ThunkAction} from 'redux-thunk' | ||
|
||
import { ThunkResult } from '../' | ||
import authorApi from '../../api/authorApi' | ||
import { RootState } from '../RootState' | ||
import { IAuthor, LOAD_AUTHORS_SUCCESS } from './types' | ||
import { OtherAction } from '../' | ||
|
||
|
||
/************************* | ||
* ACTION TYPES/CREATORS | ||
*************************/ | ||
|
||
export type LoadAuthorsSuccessAction = { | ||
type: LOAD_AUTHORS_SUCCESS, | ||
authors: IAuthor[], | ||
}; | ||
|
||
export function LoadAuthorsSuccess(authors: IAuthor[]): LoadAuthorsSuccessAction { | ||
export function loadAuthorsSuccess(authors: IAuthor[]): AuthorAction { | ||
return {type: LOAD_AUTHORS_SUCCESS, authors} | ||
} | ||
|
||
|
||
export const loadAuthors: ActionCreator< | ||
ThunkAction<Promise<Action>, RootState, void> | ||
> = () => { | ||
return async (dispatch: Dispatch<Action, RootState>): Promise<Action> => { | ||
const authors: IAuthor[] = await authorApi.getAllAuthors() | ||
return dispatch({ | ||
type: LOAD_AUTHORS_SUCCESS, | ||
authors | ||
}) | ||
/************************* | ||
* ACTION TYPE UNION | ||
*************************/ | ||
|
||
export type AuthorAction = | ||
| LoadAuthorsSuccessAction | ||
| OtherAction | ||
; | ||
|
||
|
||
/************************* | ||
* THUNKS | ||
*************************/ | ||
|
||
export function loadAuthors() : ThunkResult<void> { | ||
return async (dispatch, getState) => { | ||
const authors = await authorApi.getAllAuthors() | ||
dispatch(loadAuthorsSuccess(authors)) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ICourse } from './courses' | ||
import { IAuthor } from './authors' | ||
|
||
// Note that this class is an instance of type RootState | ||
class InitialState { | ||
authors: IAuthor[] = [] | ||
courses: ICourse[] = [] | ||
} | ||
|
||
export default new InitialState() |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AuthorAction } from './authors' | ||
import { CourseAction } from './courses' | ||
|
||
export type RootAction = | ||
| AuthorAction | ||
| CourseAction | ||
; |
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