Skip to content

Commit

Permalink
Merge pull request #33 from GetAmbassador/46_update_redux_clerk_fetch…
Browse files Browse the repository at this point in the history
…_reducer_to_merge_items_instead_of_overwriting_them

Update redux-clerk fetch reducer to merge items instead of overwriting them
  • Loading branch information
Chochek committed Mar 15, 2017
2 parents d554d63 + a21a9bb commit 3107292
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/reducers/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const success = (state, action) => {

// Merge new raw data with existing raw data
const normalizedData = normalize(action.uidField, Immutable.fromJS(responseData))
map.set('raw', state.get('raw').merge(normalizedData))
map.set('raw', map.get('raw').mergeDeep(normalizedData))
}

// Update instance array with new data
Expand Down
24 changes: 12 additions & 12 deletions test/reducers/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ describe('Reducers::Fetch', () => {
let previousState

beforeEach(() => {
previousState = Immutable.fromJS({
raw: {
123: { uid: 123, test: '123' },
234: { uid: 234, test: '234' }
},
instances: {
previousState = Map({
raw: Map([
[123, Map({ uid: 123, test: '123', field_old: 'test' })],
[234, Map({ uid: 234, test: '234' })]
]),
instances: Immutable.fromJS({
test1: {
data: [123, 234]
}
}
})
})
})

Expand All @@ -74,15 +74,15 @@ describe('Reducers::Fetch', () => {
uidField: 'uid',
instance: 'test1',
responseData: [
{ uid: 123, test: 'name' },
{ uid: 123, test: 'name', field_new: 'test' },
{ uid: 345, test: '345' }
],
options: {}
}

const expectedResult = {
raw: {
123: { uid: 123, test: 'name' },
123: { uid: 123, test: 'name', field_old: 'test', field_new: 'test' },
234: { uid: 234, test: '234' },
345: { uid: 345, test: '345' }
},
Expand All @@ -106,7 +106,7 @@ describe('Reducers::Fetch', () => {

const expectedResult = {
raw: {
123: { uid: 123, test: 'name' },
123: { uid: 123, test: 'name', field_old: 'test' },
234: { uid: 234, test: '234' }
},
instances: {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Reducers::Fetch', () => {

const expectedResult = {
raw: {
123: { uid: 123, test: '123' },
123: { uid: 123, test: '123', field_old: 'test' },
234: { uid: 234, test: '234' },
345: { uid: 345, test: '345' },
456: { uid: 456, test: '456' }
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('Reducers::Fetch', () => {

const expectedResult = {
raw: {
123: { uid: 123, test: '123' },
123: { uid: 123, test: '123', field_old: 'test' },
234: { uid: 234, test: '234' },
345: { uid: 345, test: '345' },
456: { uid: 456, test: '456' }
Expand Down

0 comments on commit 3107292

Please sign in to comment.