This file contains hidden or 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
| apiRequest(isCreate, requestData(createTeam), teamsCreateSuccess, teamsCreateFailure), | |
| apiRequest(isUpdate, requestData(updateTeam), teamsUpdateSuccess, teamsUpdateFailure) |
This file contains hidden or 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
| notify( | |
| isTaskTypeCreate, | |
| "The project's task type was successfully created.", | |
| "The project's task type could not be created." | |
| ), |
This file contains hidden or 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
| export type AppState = {| | |
| ui: Ui, | |
| auth: Auth, | |
| entities: Entities, | |
| |}; |
This file contains hidden or 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
| https://github.com/Automattic/happiness-scheduler-frontend/blob/master/src/state/index.js#L46-L50 |
This file contains hidden or 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
| function asyncReaction<T: ActionTypes>(detector: Detector<T>, handler: Handler<T>): AppMiddleware { | |
| return store => next => action => { | |
| const detected = detector(action); | |
| if (detected !== null) { | |
| handler(detected, store.getState()).then(store.dispatch); | |
| } | |
| return next(action); | |
| } | |
| } |
This file contains hidden or 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
| const middleware: AppMiddleware = store => next => action => { | |
| const usersCreate = isProjectsCreate(action); | |
| if (usersCreate !== null) { | |
| // do something with usersCreate | |
| createProjectHTTP(usersCreate, store.getState()).then(store.dispatch); | |
| } | |
| return next(action); | |
| } |
This file contains hidden or 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
| type Handler<T: ActionTypes> = (T, AppState) => Promise<ActionTypes>; | |
| const createProjectHTTP: Handler<ProjectsCreate> = async (action, state) => { | |
| try { | |
| const response = await createProject(action.stage.value); | |
| return projectsCreateSuccess(response.data); | |
| } catch (error) { | |
| return projectsCreateFailure(action.stage.value); | |
| } | |
| } |
This file contains hidden or 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
| type Handler<T: ActionTypes> = (T, AppState) => Promise<void> | void; |
This file contains hidden or 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
| const middleware: AppMiddleware = () => next => action => { | |
| const usersCreate = isProjectsCreate(action); | |
| if (usersCreate !== null) { | |
| // do something with usersCreate | |
| } | |
| return next(action); | |
| } |
This file contains hidden or 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
| type Detector<T: ActionTypes> = ActionTypes => ?T; | |
| const isProjectsCreate: Detector<ProjectsCreate> = action => | |
| action.type === 'PROJECTS_CREATE' ? action : null; |