Last active
May 16, 2019 18:40
-
-
Save iagodahlem/a41bcc7746028601bab8084ac1f1d861 to your computer and use it in GitHub Desktop.
Scalable Frontend - The State Layer - Article Reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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