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

feat(dataReducer): revert merged data removal #324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/reducers/dataReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from 'lodash';
import { setWith } from 'lodash/fp';
import { setWith, assign } from 'lodash/fp';
import { actionTypes } from '../constants';
import { pathFromMeta, preserveValuesFromState } from '../utils/reducers';

Expand Down Expand Up @@ -59,11 +59,13 @@ export default function dataReducer(state = {}, action) {
state,
);
}
// Otherwise merge with existing data
const mergedData = assign(previousData, data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will prevent removing a param from an object that is removed elsewhere - what is the goal here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is meant to revert back an existing functionality that has been later removed (while kept in rrf - firebase), data merging.
When for a given collection you change the query to fetch new data (or next page for that matters) new data should be merged with existing data, at the moment is getting replaced.
What the PR is doing is just reverting back the files to their previous status (as mentioned in the issue open #294)

// Set data to state (with merge) immutabily (lodash/fp's setWith creates copy)
return setWith(
Object,
meta.storeAs ? [meta.storeAs] : pathFromMeta(meta),
data,
mergedData,
state,
);
case DOCUMENT_MODIFIED:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/reducers/dataReducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('dataReducer', () => {
`${collection}.${doc}.newData.field`,
data[doc].newData.field,
);
expect(result).to.not.have.nested.property(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was in place for a reason - not removing a value which is removed from the object will cause stale data in certain situations

expect(result).to.have.nested.property(
`${collection}.${doc}.originalData.some.val`,
existingState[collection][doc].originalData.some.val,
);
Expand Down