Last active
August 28, 2018 13:35
-
-
Save sachinKumarGautam/05eaf5d82b753a2e8b7c75654cdd53c9 to your computer and use it in GitHub Desktop.
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
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