Comments (4)
Hi,
I'm not sure I agree with you at all here, but I'm happy to discuss further. My main issues are:
-
The store represents the DOM of the Vue Single Page Application
. No, thejsonapi-vuex
store is set up as a module, and represents the API, in a restructured format. It is in no way connected to the DOM of the SPA, and can be used without ever instantiating a DOM. It is not the root store. -
it is an anti-pattern to put the json:api document from the http service in the Vue store
. No - making API calls in stoeactions
is a commonly recommended approach to dealing with async data from API requests in Vue applications. An example of this is even given in the official Vuex documentation: https://vuex.vuejs.org/guide/actions.html#dispatching-actions -
Instead of that implement a plain Node.js module outside Vue Components
. No - by using a Vuex module with it's own store, we get all the benefits of separation of concerns, with a Vuex-standard way to access the data. If you want to access the API and restrcutre the results, this restructured data must be made available to the Vue app. Vuex getters on a store are a much more efficient and neat solution than a vanilla app with it's own non-standard store, and an extra 'wrapper' that translates between Vue and this external module. -
why to load the document in the store?
. Because otherwise every data access will either require a new request to the API (inefficient), or the end-user will be responsible for storing the restructured data that is passed to them. Since they're using Vue, and Vuex is the de-facto store, they'd likely want to store it in Vuex, so why not do this initially?
from jsonapi-vuex.
Hi, I recognize I am just a beginner on IT. (hobby developer). I am reading your answers to see if you might be right.
I have still my main objection but I am not sure to be right:
https://vuex.vuejs.org/guide/actions.html#dispatching-actions
I believe in the Vue documentation they describe an action in the store that consist of:
- An asynchronous http request to a http service (or microservice)
- Load that json:api document response in some temporary variable
- mutate some data in the store according the information received + some postprocessing
But the http response document from the microservice is not loaded in the store of the Single Page Application because this information is data that the SPA needs to know but not data of the SPA state itself.
Keep this sentence: The http response is not state data of the SPA
from jsonapi-vuex.
The steps you describe in 1-3 above is effectively what jsonapi-vuex
is doing. It makes an http request to a RESTFUL api, translate the 'raw' JSONAPI data into restructured data, and then commits that to the store.
In the Vuex documentation example, the data fetched from the API and committed to the store is information on a shopping cart transaction. While there is no example SPA code, it seems obvious that the SPA is going to display the state of the shopping cart success/failure. I'm not sure how this doesn't count as state data of the SPA.
For completeness it's worth adding that jsonapi-vuex
uses a module, not the 'default' or 'root' store. This means that all the data is kept in it's 'own area' under the jv
store module name. If the SPA has it's own state, then this will be kept separate from the API data.
It's also worth noting that if you object to storing API data in a Vuex store, then the module can be used without touching a store at all. Simply use the search
action and the (restructured) data will be returned from the action as usual, but no store changes will be made.
Of course this then means that any tracking of state changes has to be done yourself in your own code. For this you probably want to use some kind of standalone store - such as a Vuex store module...
from jsonapi-vuex.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonapi-vuex.
Related Issues (20)
- state should return function HOT 9
- Struggle to access some related / included data HOT 5
- Misunderstanding or ? HOT 7
- Using href url HOT 4
- Problem when sorting with numbers HOT 1
- Option preserveJson ignored HOT 2
- Encoded type and id might cause to return undefined instead of stored object HOT 2
- Webpack - Failed to compile Error HOT 2
- How to normalize keys from server HOT 2
- TypeError: property "system" is non-configurable and can't be deleted HOT 3
- HasMany relationships HOT 8
- How do I clear all records of a specific type?
- highlight highlight-source-js
- GetRelated constructs incorrect URLs instead of following relationship links HOT 5
- Pinia support HOT 3
- Missing option to deactivate url encoding in deleteRecord HOT 2
- CWE-1321 Vulnerability in lodash.set in version 4.5.3 HOT 1
- Meta object is missing when sending a PATCH request HOT 3
- Cannot access included records when using api/search HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi-vuex.