Skip to content

Instantly share code, notes, and snippets.

@andresmijares
Created March 19, 2017 20:08
Show Gist options
  • Save andresmijares/fa38b6b1f1505f1fd43db3b82e954ee2 to your computer and use it in GitHub Desktop.
Save andresmijares/fa38b6b1f1505f1fd43db3b82e954ee2 to your computer and use it in GitHub Desktop.
javascript
import {marketplace} from 'gateways'
import {take, put, call} from 'redux-saga/effects'
import {backendService, notificationService} from 'services'
function* createOrder () {
try {
/* Send Order to PouchDb and get the ID */
const {payload} = yield take('ORDER_CREATE')
/* Send the ID to the Backend API */
const order = yield call(backendService.create, payload)
/* Release the UI, the user doesn't care about the rest*/
yield put({
type: 'ORDER_CREATE_COMPLETED',
payload: order
})
/* Notify the market places */
const [m1, m2, m3] = yield [call(marketplace, 'marketOne', payload), call(marketplace.exec, 'marketTwo', payload), call(marketplace.exec, 'marketThree', payload, order)]
/* Hit the Notification service to send emails... */
yield call(notificationService.sendEmail, m1, m2, m3)
yield put({type: 'ORDER_CREATE_NOFITICATIONS_COMPLETED'})
} catch (e) {
yield put({type: 'ERROR_CREATE_ORDER', payload: e})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment