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

Preserve order of collection when updating an object. #74

Merged
merged 2 commits into from
Oct 7, 2016

Conversation

Petesta
Copy link
Contributor

@Petesta Petesta commented Oct 6, 2016

No description provided.

@Petesta
Copy link
Contributor Author

Petesta commented Oct 6, 2016

This PR aims to preserve the ordering of a collection when making an update and references this issue.

Currently, after making an update this what the response will come back as.

const state = [ { type: 'users',
    id: '1',
    attributes: { name: 'John Doe' },
    relationships: { companies: [Object] } },
  { type: 'users',
    id: '2',
    attributes: { name: 'Emily Jane' },
    relationships: { companies: [Object] } } ];

const updatedState = [ { type: 'users',
    id: '2',
    attributes: { name: 'Emily Jane' },
    relationships: { companies: [Object] } },
  { type: 'users',
    id: '1',
    attributes: { name: 'Sir John Doe' },
    relationships: { tasks: [Object] } } ];

With the preservation of order here is what we get.

const state = [ { type: 'users',
    id: '1',
    attributes: { name: 'John Doe' },
    relationships: { companies: [Object] } },
  { type: 'users',
    id: '2',
    attributes: { name: 'Emily Jane' },
    relationships: { companies: [Object] } } ]
const updatedState = [ { type: 'users',
    id: '1',
    attributes: { name: 'Sir John Doe' },
    relationships: { tasks: [Object] } },
  { type: 'users',
    id: '2',
    attributes: { name: 'Emily Jane' },
    relationships: { companies: [Object] } } ]

@egeriis
Copy link
Collaborator

egeriis commented Oct 6, 2016

Would've loved to see the test in a commit before the fix, then it's easier to review that it's failing without your fix :)

@Petesta
Copy link
Contributor Author

Petesta commented Oct 6, 2016

@egeriis Can you clarify your strategy here? Do you want me to submit a failing test, you look at it, then I fix it or just create a new test and merge?

@egeriis
Copy link
Collaborator

egeriis commented Oct 7, 2016

@Petesta No action needed for this. But if you are making two separate commits, first one is a failing test the next one is the fix. That should prompt GitHub to display that the first commit has a failing test and that the next one resolves this :)

@egeriis
Copy link
Collaborator

egeriis commented Oct 7, 2016

Example:
image

@egeriis
Copy link
Collaborator

egeriis commented Oct 7, 2016

We will merge and publish today :)

@egeriis egeriis merged commit e425c57 into redux-json-api:master Oct 7, 2016
@egeriis egeriis modified the milestone: v1.5.3 Oct 7, 2016
@egeriis
Copy link
Collaborator

egeriis commented Oct 7, 2016

Published to npm

@Petesta Petesta deleted the preserve-order branch October 28, 2016 13:53
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

Successfully merging this pull request may close these issues.

None yet

2 participants