Можно сделать
isLoading и хранилище сущностей объектом:
const initialState: {
entities: {}.
isLoading: {
'ALL': false,
},
isError: {
'ALL': false,
}
}
const someEntityReduser = (state = initalState, action) => {
const { type, payload } = action;
switch (type) {
case GET_ALL_ENTITIES_REQUEST:
return {
...state,
isLoading: {
...state.isLoading,
'ALL': true,
},
isError: {
...state.isError,
'ALL': false,
},
};
case GET_ALL_ENTITIES_SUCCESS:
return {
...state,
entities: payload, // либо нормализация если приходят массивом
isLoading: {
...state.isLoading,
'ALL': false,
},
};
case UPDATE_ENTITY_REQUEST:
return {
...state,
isLoading: {
...state.isLoading,
[payload.id]: true,
},
isError: {
...state.isError,
[payload.id]: false,
},
};
case UPDATE_ENTITY_SUCCESS:
return {
...state,
entities: {
...state.entities,
[payload.id]: payload,
},
isLoading: {
...state.isLoading,
[payload.id]: false,
},
};
/* other cases */
}
}