Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active September 20, 2018 15:17
Show Gist options
  • Save ajcrites/593cf42056d6a58dba5bbd223903bf55 to your computer and use it in GitHub Desktop.
Save ajcrites/593cf42056d6a58dba5bbd223903bf55 to your computer and use it in GitHub Desktop.
// 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;
}
}
// 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