Issue on page /react/external_data.html [16.2. Writing Middleware]
Issue
ESLint Warning: import/no-anonymous-default-export in the code snippet of the topic 16.2. Writing Middleware
Link to Community Discussion. Assigning this issue to myself.
Incorrect Code Snippet
export default store => next => action => {
const { request, type, ...rest } = action;
if (!request) {
return next(action);
}
next({ ...rest, type: `${type}_PENDING` });
const actionPromise = fetch(`http://localhost:3001${request.path}`, {
method: request.op,
body: request.data && JSON.stringify(request.data)
});
actionPromise.then(response => {
response.json().then(data => next({ data, type: `${type}_SUCCESS` }));
});
return actionPromise;
};
Corrected Code Snippet
const api = store => next => action => {
const { request, type, ...rest } = action;
if (!request) {
return next(action);
}
next({ ...rest, type: `${type}_PENDING` });
const actionPromise = fetch(`http://localhost:3001${request.path}`, {
method: request.op,
body: request.data && JSON.stringify(request.data)
});
actionPromise.then(response => {
response.json().then(data => next({ data, type: `${type}_SUCCESS` }));
});
return actionPromise;
};
export default api;
Please submit a PR for this. Thank you!
@stevepiercy, considering this & #590. Should I make two different PR for 2 different issues or a single one? (Like, which approach will be better)
Thanks for asking. For the Training repo, we like to make it easy to contribute, and not make busy work. I think for a few number of small changes, combining them into a single pull request is fine. Also because this is for a single training, it makes sense to get it all done in a single swoop.
@stevepiercy LineFeed is LF right?
I don't understand the question. Do you mean what are the line endings for files in the repo?
Yes, exactly. Sorry, my bad couldn't frame my question right.
Honestly, I don't know. It "just works" for me. On my local machine, files use LF. I assume the repo uses LF as well.
Great, I use Mac as well. So shouldn't be a problem for me.