Skip to content

Commit

Permalink
allow responses without data envelope. workaround for #6 until #19 is…
Browse files Browse the repository at this point in the history
… done
  • Loading branch information
devvmh committed Jul 20, 2016
1 parent c6804d8 commit 887829c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function byIdReducer(state = byIdInitialState, action) {
switch (action.type) {
case FETCH_SUCCESS:
const data = state.toJS()
action.payload.data.forEach((record) => {
const payload = ('data' in action.payload) ? action.payload.data : action.payload
payload.forEach((record) => {
data[record.id] = {
record,
fetchTime: action.meta.fetchTime,
Expand Down Expand Up @@ -110,10 +111,13 @@ function collectionReducer(state = collectionInitialState, action) {
.set('fetchTime', 0)
.set('error', null)
case FETCH_SUCCESS:
const ids = action.payload.data.map((elt) => elt.id)
const originalPayload = action.payload || {}
const payload = ('data' in originalPayload) ? action.payload.data : action.payload
const otherInfo = ('data' in originalPayload) ? originalPayload.delete('data') : {}
const ids = payload.map((elt) => elt.id)
return state.set('params', fromJS(action.meta.params))
.set('ids', fromJS(ids))
.set('otherInfo', fromJS(action.payload || {}).delete('data'))
.set('otherInfo', fromJS(otherInfo))
.set('error', null)
.set('fetchTime', action.meta.fetchTime)
case FETCH_ERROR:
Expand Down

0 comments on commit 887829c

Please sign in to comment.