Last active
July 28, 2017 09:40
-
-
Save aaronmcadam/d51b4c63ecdc7b5e5b15a9edf4da180b to your computer and use it in GitHub Desktop.
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 requestAddMessage = (sources) => { | |
const message$ = sources.ACTION | |
.filter((action) => action.type === 'ADD_MESSAGE') | |
.map((action) => action.payload); | |
const request$ = message$.map((payload) => { | |
return { | |
url: `/api/conversations/${payload.conversationId}/messages`, | |
category: 'addMessage', | |
method: 'POST', | |
withCredentials: true, | |
send: payload.formData, | |
progress: true, | |
references: { | |
messageId: payload.messagePreview.id, | |
}, | |
}; | |
}); | |
const response$ = sources.HTTP | |
.select('addMessage') | |
.map(normaliseAPIErrors) | |
.flatten(); | |
const messageResponse$ = response$ | |
.filter((x) => x.type === 'application/json') | |
.map(({ request: { references }) => addMessageSuccess({ messageId: references.messageId })); | |
return { | |
ACTION: messageResponse$, | |
HTTP: request$, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to avoid that
let
, butmessageId
is set in therequest$
and is needed for themessageResponse$
.Or is it best to leave it there to keep the code "simple"?