Created
March 22, 2017 07:11
-
-
Save RealDeanZhao/2874dca6172383b5d6020d366717a825 to your computer and use it in GitHub Desktop.
redux-observable-epic-biolerplate-with-concat
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
export const settlementEpic = { | |
fetchDocumentList: (action$) => { | |
return action$.ofType(settlementAction.fetchDocumentList.getType()) | |
.map(action => action.payload) | |
.switchMap(payload => { | |
const userId = window.localStorage.getItem('userid'); | |
let path = `/api/v1/documents?ownerId=${userId}`; | |
if (payload && payload.query && payload.query.settlementBuyer) { | |
path = path.concat(`&buyer=${payload.query.settlementBuyer}`); | |
} | |
return ajax$.getJSON(path).map(json => | |
settlementAction.receiveDocumentList(json.documents) | |
); | |
}) | |
.switchMap(prevAction => | |
concat$( | |
of$(prevAction), | |
of$(push('/settlement/documents')), | |
of$(settlementAction.createSettlement({ created: true })) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment