Skip to content

Decouple AJAX calls in JS logic and remove unnecessary return values from AJAX endpoints #131

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

Open
1 task done
felixarntz opened this issue Mar 31, 2023 · 0 comments
Open
1 task done
Labels
Code Quality [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@felixarntz
Copy link
Member

Is your enhancement related to a problem? Please describe.

Currently, all AJAX calls made from the admin JS file are chained directly to each other, with the response data from one request being passed as data to the next. This has led to an awkward requirement where we have to return certain data from the PHP AJAX endpoints just because the next endpoint needs them rather than because it actually makes sense to return them from the endpoint. We should avoid that and truly decouple the AJAX endpoints.

We should decouple all the functions in JS so that they don't just accept a data "dump" parameter, but individual parameters for what they truly need. For example:

  • getChecksToRun( plugin ): Its AJAX endpoint should return just the check slugs, and then they should be put into a variable.
  • setUpEnvironment( plugin, checks ): Its AJAX endpoint should return just a success message, nothing else.
  • runChecks( plugin, checks ): AJAX endpoint is already good as is, just the JS function should have the new cleaner signature.
  • cleanUpEnvironment(): Can basically remain as is.

Another good idea that we could include here would be to make a wrapper around the fetch function since we always call it the same way, e.g. fetchAJAX( data ), which includes the ajaxurl, method: 'POST' and credentials: 'same-origin' bits, and it could also automatically include the nonce in the body data since that needs to be present in every request.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature Code Quality labels Mar 31, 2023
@eclarke1 eclarke1 moved this to Backlog in Plugin Check Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Quality [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant