Last active
September 20, 2018 15:17
-
-
Save ajcrites/593cf42056d6a58dba5bbd223903bf55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Example | |
// Error handling and such omitted for simplicity | |
export const profileEpic = action => action.pipe( | |
ofType(SEARCH_PROFILE), | |
switchMap(term => getProfileByTerm(term).pipe( | |
map(({ body }) => { | |
let name = body.name; | |
if (name && name !== 'Andrew') { | |
name = name.toUpperCase(); | |
} else { | |
name = name.split('n').join(''); | |
} | |
new SearchProfileSuccessAction(name)), | |
} | |
), | |
); | |
export function profileReducer(state = { name: '' }, action) { | |
switch (action.type) { | |
case SEARCH_PROFILE_SUCCESS: | |
return { ...state, name: action.payload }; | |
default: | |
return state; | |
} | |
} |
This file contains hidden or 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
// Better Example | |
// Error handling and such omitted for simplicity | |
export const profileEpic = action => action.pipe( | |
ofType(SEARCH_PROFILE), | |
switchMap(term => getProfileByTerm(term).pipe( | |
map(({ body }) => new SearchProfileSuccessAction(body)), | |
), | |
); | |
export function profileReducer(state = { name: '' }, action) { | |
switch (action.type) { | |
case SEARCH_PROFILE_SUCCESS: | |
let name = action.payload.name; | |
if (name && name !== 'Andrew') { | |
name = name.toUpperCase(); | |
} else { | |
name = name.split('n').join(''); | |
} | |
return { ...state, name }; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment