Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ describe('gndownload reducer', () => {
}
});
});
it('downloadMetaDataComplete does not mutate the previous state', () => {
const previousLinkState = { 1: true };
const state = { downloads: { ISO: previousLinkState, DublinCore: {} } };
gndownload(state, downloadMetaDataComplete('ISO', 1));
// a reducer must be pure: the previous state object must remain untouched
expect(previousLinkState).toEqual({ 1: true });
});
});
14 changes: 6 additions & 8 deletions geonode_mapstore_client/client/js/reducers/gndownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ function gnDownload(state = defaultState, action) {
};
}
case DOWNLOAD_METADATA_COMPLETE: {
const newState = { ...state };
const linkType = action?.link?.split(' ').join('');
const downloads = newState.downloads[linkType];
delete downloads[action.pk];
// copy the link bucket before deleting so the previous state is not mutated
const remaining = { ...(state.downloads[linkType] || {}) };
delete remaining[action.pk];
Comment thread
Valyrian-Code marked this conversation as resolved.
Outdated
return {
...newState,
...state,
downloads: {
...newState.downloads,
[linkType]: {
...downloads
}
...state.downloads,
[linkType]: remaining
}
};
}
Expand Down