beauby / jsonapi-datastore

JavaScript client-side JSON API data handling made easy.
MIT License
195 stars 40 forks source link

Ordering of results #34

Open dimoreira opened 7 years ago

dimoreira commented 7 years ago

When requesting an ordered endpoint of my API by some custom order field (like: updated_at DESC), my results gets reordered by id when parsed by the library.

There is some way to not reorder the results, just parse them in the order they appear in the API response?

beauby commented 7 years ago

The primary data should remain in the same order. Are you referring to the included data?

dimoreira commented 7 years ago

The primary data that is reordering basically because the simple way that browsers reshuffle object keys. Try this on Chrome console: {12: 'a', 2: 'b'}

This is the way my team solved the problem: https://github.com/redvulps/jsonapi-datastore/commit/75bba57bd04e19b38be91f2a183b235093d08d2f

beauby commented 7 years ago

That is some interesting information I was not aware of. Keeping the same order should be the default (and probably only) behavior IMO. Would you mind issuing a PR?

dimoreira commented 7 years ago

@redvulps Could you send a PR to the main repo when you have time?

redvulps commented 7 years ago

hm, should we keep the current behavior as default? or return the same sorting as in the request as default?

beauby commented 7 years ago

@redvulps I would favor returning the same sorting as in the request only. The current behavior is in fact undefined.

ikristher commented 7 years ago

I too experienced this problem. How can i solve this problem?