Closed jsherbert closed 7 years ago
Nothing prevents you from implementing your own reducers next to the ones provided by reduxCrud! IMHO the structure you propose might not suit everybody's need.
Just to give you a concrete example, let's say you want to have a busy flag when fetching.
const busyReducerFor(name) => {
const actionTypes = reduxCrud.actionTypesFor(name);
return (state = false, action) => {
switch (action.type) {
case actionTypes.fetchStart:
return true
case actionTypes.fetchSuccess:
case actionTypes.fetchError:
return false
}
return state
}
}
const reducer = combineReducers({
records: reduxCrud.Map.reducersFor('users'),
busy: busyReducerFor('users')
})
@hwaterke, yeah, you're absolutely right, it's probably best to keep redux-crud as a smaller library and add functionality as needed. I can imagine package size/complexity spiralling as new functionality is added and differing use cases stretch the API.
Thanks for the example :)
It would be useful to be able to store request meta.
This would open the door to pagination, storing the request order in 'map' mode, a 'busy' flag for fetch operations, etc.
It would require us to store records in a property within the reducer state.
Instead of the state looking like
{ ...records }
, I guess the dream might beso we can do something along the lines of
const resultsForPage = selectPage(state, 1).map(id => selectRecord(state, id))
but I'm happy to start with
Possible concerns:
state[reducerKey]records
for their records rather than going straight tostate[reducerKey]
. We can either accept this as a breaking change or introduce the envelope/meta approach as an option and use a selector across the library to get the record list.What do you think, @sporto, worth a PR?