-
Notifications
You must be signed in to change notification settings - Fork 19
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
Removing .attributes
and .data
#20
Comments
This would definitely be nicer; I frequently forget to add I've deferred this decision so far because it takes some thought to add in the translation from JSON:API data format to a more usable format and back. Here's the main API design question I have about this change: (let me know if you have thoughts!) Right now with the
If we change the returned records to be the new flatter format, it would be nontrivial for the
Do you think option 1 would be a step in the right direction, so that reads are simpler even though writes are still as verbose? Or would you rather wait for an update until if/when I can come up with a design for option 2? |
Hmm that is a tough call. I can see it being annoyingly difficult to update complex records with option 1. Would the user just have to pass in the fields they want to update? Option 2 seems to make more sense to me especially if you sync your support of JSON:API with a particular version of the spec. I wish I could give more advice on the best way to implement this. |
IMO the library should stay with the JSON:API spec. When you start flattening data you would gain a bit less verbose code but possibly loose the ability to differentiate. Next to that .attributes should still be available for backward compatibility (or you have a breaking change). Which would make a dump of the data in a object have duplicate entries. Taking that in consideration, I think it could become nasty mess. Edit: Maybe access-functions would be helpful |
I suggest to look on https://github.com/olosegres/jsona. This is data formatter for JSON:API that can covert data attributes and relationships to simple model like:
and deserialize it back to JSON:API format easily. I think it will be good to add as store config "dataProvider" that will serialize and deserialize from JSON:API JSON format into simple JS Object and back. I am also working on library that using Jsona as "data formatter" for the requests. |
you could also in theory have getters that return the flattened attributes. this way if you want a simpler way to display data, you could do: |
FYI, this library will be unmaintained going forward. If you need new features or fixes, I recommend forking the repo and making changes, or finding an alternate library that meets your needs. |
It gets tedious having to type
user.attributes.username
,user.relationships.todos.data
. Could this library restructure the data to the more user-friendly formatuser.username
anduser.todos
respectively?The text was updated successfully, but these errors were encountered: