Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iagodahlem/a41bcc7746028601bab8084ac1f1d861 to your computer and use it in GitHub Desktop.
Save iagodahlem/a41bcc7746028601bab8084ac1f1d861 to your computer and use it in GitHub Desktop.
Scalable Frontend - The State Layer - Article Reducer
const articlesReducer = (state = initialState, action) => {
switch (action.type) {
case 'RECEIVE_DATA':
const articles = replaceRelationById(action.data, 'author')
return {
...state,
byId: byId(articles),
allIds: allIds(articles),
}
default:
return state
}
}
const authorsReducer = (state = initialState, action) => {
switch (action.type) {
case 'RECEIVE_DATA':
const authors = extractRelation(action.data, 'author')
return {
...state,
byId: byId(authors),
allIds: allIds(authors),
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment