Created
June 14, 2018 10:12
-
-
Save iamdey/66772d8709edcf6bdf971bba64f62d52 to your computer and use it in GitHub Desktop.
typing w/ flow
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
// @flow | |
import { createMessage as createMessageBase, requestMessage, addToCollection } from '../../../store/modules/message'; | |
import { tryCatchAxiosAction } from '../../../services/api-client'; | |
/* :: | |
type Message = { | |
message_id: string | |
} | |
*/ | |
/* :: | |
type createMessageType = ({ message: Message }) => (dispatch: function) => Promise<Message> | |
*/ | |
export const createMessage /* : createMessageType */ = ({ message }) => | |
async (dispatch) => { | |
await dispatch(createMessageBase({ message })); | |
const messageUpToDate = await tryCatchAxiosAction(() => | |
dispatch(requestMessage(message.message_id))); | |
await dispatch(addToCollection({ message: messageUpToDate })); | |
return messageUpToDate; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment