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

Placing an http response in the Vue store is an anti-pattern #289

Open
cmartinezrazola opened this issue Feb 13, 2021 · 0 comments
Open

Comments

@cmartinezrazola
Copy link

A Vue instance is like a backend inside the frontend. The store represents the DOM of the Vue Single Page Application. The SPA practices CORS (Cross Origin Resource Sharing) with a true backend on whatever domain. The http service responds with a json:api document representing generic information to be rendered in the browser or for other purpose. In both cases it is an anti-pattern to put the json:api document from the http service in the Vue store because the store represents the DOM of the SPA. Instead of that implement a plain Node.js module outside Vue Components and the store to place the json:api response and implement CRUD AJAX procedures. I see the json:api document similar to html labels but representing information for whatever purpose. That document is loaded asynchronously by the SPA but: why to load the document in the store? The store is the DOM (Document Object Model) of the SPA. Components in the SPA may have a detailed DOM through computed properties and getters implemented in the store.
Using a json:api document as the data structure of a Single Page Application is, in itself, an anti-pattern as well.
The programmer of each SPA should chose the data structure that best fit in the Application. When the SPA make an asynchronous http request to a remote http service, the service will respond with an json:api document. But the http service doesn't know the data structure of the consumer Single Page Application. So, to provide a standard data-structure-agnostic response, the Content-Type json:api has been specified. The http service responds with a json:api document that is data-structure-agnostic (unopinionated) regarding data structure of the consuming Single Page Application. So the Content-Type json:api is just a standard agnostic response that every http service should implement.

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

No branches or pull requests

1 participant