Skip to content

Instantly share code, notes, and snippets.

@sachinKumarGautam
Last active August 28, 2018 13:35
Show Gist options
  • Save sachinKumarGautam/05eaf5d82b753a2e8b7c75654cdd53c9 to your computer and use it in GitHub Desktop.
Save sachinKumarGautam/05eaf5d82b753a2e8b7c75654cdd53c9 to your computer and use it in GitHub Desktop.
export function getData(action$) {
return action$.ofType(GET_DATA) // action type for epic to listen changes
.switchMap(data => { // switchMap is used to always get latest stream ( i.e switch to new stream )
return Observable.ajax(getData(data.id)) //some id
.flatMap(results => { // flatmap is used to flatten the inner observables
return Observable.of(
getDataSuccess(results) // success action
)
})
.catch((error, source) => {
return Observable.of(getDataFailure(error)) // failure action
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment