Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Last active July 28, 2017 09:40
Show Gist options
  • Save aaronmcadam/d51b4c63ecdc7b5e5b15a9edf4da180b to your computer and use it in GitHub Desktop.
Save aaronmcadam/d51b4c63ecdc7b5e5b15a9edf4da180b to your computer and use it in GitHub Desktop.
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$,
};
};
@aaronmcadam
Copy link
Author

aaronmcadam commented Jul 27, 2017

I would like to avoid that let, but messageId is set in the request$ and is needed for the messageResponse$.
Or is it best to leave it there to keep the code "simple"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment