Skip to content

Instantly share code, notes, and snippets.

@gastonmorixe
Last active September 18, 2018 11:36
Show Gist options
  • Save gastonmorixe/cf6f40578524ddd085dd to your computer and use it in GitHub Desktop.
Save gastonmorixe/cf6f40578524ddd085dd to your computer and use it in GitHub Desktop.
Redux React CombineReducers Discussion [With Dan Abramov]
import { combineReducers } from 'redux'
import reduceReducers from 'reduce-reducers'
import { invites } from './Invites'
import { claimInvite } from './ClaimInvite'
import { app } from './App'
import * as actions from '../constants/ActionTypes'
import {mapping, parseRemotePersonJSON} from './App'
const combinedReducer = combineReducers({
invites,
app,
claimInvite,
})
const rootAccessReducer = (state, action) => {
switch (action.type) {
case `${actions.REQUEST_INVITE}_FULFILLED`:
return { ...state,
app:{...state.app,
loggedPerson: {...state.app.loggedPerson,
...parseRemotePersonJSON(action.payload.person),
authToken: state.app.loggedPerson.authToken
}
},
claimInvite:{...state.claimInvite,
inviteRequest: {...state.claimInvite.inviteRequest,
state: 'loaded'
}
}
}
default:
return state
}
}
const rootReducer = reduceReducers(combinedReducer, rootAccessReducer)
export default rootReducer
@gastonmorixe
Copy link
Author

for historical and educational reasons, the happy ending

from dan: @gastn___ I like the last approach you suggested. 

https://twitter.com/dan_abramov/status/679832619333345280

@phamcharles
Copy link

@imton,

I'm currently in the boat you were in during the time of this gist. I was hoping you could help shed some light. How did you handle higher order components/reducers that depended on other primitive reducers and do so with async fetch calls? Did redux-promise-middleware/redux-saga seem end up feeling like a good fit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment