Closed leetharris closed 6 years ago
Library works with collections. Every element on collection has the resource id as key.
Javascript sort collections by key. On my mind, we have only solution: replace collections for arrays. This solution is very aggressive, because we need change a lot of features. Collections are very fast, because we save cache on memory and browser index db; we need only ask if element exists. If we migrate to array, we need on every interaction traverse all data (imagine relations on each resource of a collection).
Another better idea?
We actually made our own workaround for this which may give you some inspiration on how you could handle it in your package.
We created a middleware that checked all incoming arrays and assigned an array_order
attribute to each item in the collection.
Then we sorted our tables by this array_order
attribute on each resource. Worked out pretty well!
Thanks for making this package!
@leetharris Could you share your code on this? @pablorsk The order should be based on the server or there should be a sort option. Automatically sorting by ID defeats the purpose of what a lot of this package does, especially since jsonapi itself supports sorting.
As the title states, this package sorts all incoming data by "id" and does not preserve the original order.
This is a problem as we have specific ordering coming out of our backend based on remote "sort" parameters (supported by the JSON-API spec).