Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on page /react/external_data.html [16.2. Writing Middleware] #591

Open
avimishra18 opened this issue Mar 12, 2022 · 8 comments
Open

Comments

@avimishra18
Copy link
Contributor

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;
@stevepiercy
Copy link
Contributor

Please submit a PR for this. Thank you!

@avimishra18
Copy link
Contributor Author

@stevepiercy, considering this & #590. Should I make two different PR for 2 different issues or a single one? (Like, which approach will be better)

@stevepiercy
Copy link
Contributor

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.

@avimishra18
Copy link
Contributor Author

@stevepiercy LineFeed is LF right?

@stevepiercy
Copy link
Contributor

I don't understand the question. Do you mean what are the line endings for files in the repo?

@avimishra18
Copy link
Contributor Author

avimishra18 commented Mar 12, 2022

Yes, exactly. Sorry, my bad couldn't frame my question right.

@stevepiercy
Copy link
Contributor

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.

@avimishra18
Copy link
Contributor Author

Great, I use Mac as well. So shouldn't be a problem for me.

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

No branches or pull requests

2 participants