Skip to content

Instantly share code, notes, and snippets.

@alextes
Created December 16, 2016 14:09
Show Gist options
  • Save alextes/a8758f5764195fa883d6cd4a9c18f1a2 to your computer and use it in GitHub Desktop.
Save alextes/a8758f5764195fa883d6cd4a9c18f1a2 to your computer and use it in GitHub Desktop.
// style 1
function asynchronouslyConstructTransformedObject(order) {
return Promise.try(() => {
return Promise.props(Object.assign({}, order, {
date: order.date,
item: getItem(order.item),
payments: Promise.map(order.payments, (paymentObject) => {
return Promise.props({
payment: getPayment(paymentObject.payment),
amountCents: paymentObject.amountCents,
states: Promise.map(paymentObject.states, (state) => {
return getState(state);
})
});
}),
paymentMethod: getPaymentMethod(order.paymentMethod),
user: getUser(order.user),
}));
});
}
// style 2
function asynchronouslyConstructTransformedObject(order) {
return Promise.try(() => {
const payments = Promise.map(order.payments, paymentObject =>
Promise.props({
payment: getPayment(paymentObject.payment),
amountCents: paymentObject.amountCents,
states: Promise.map(paymentObject.states, state => getState(state)),
}));
return Promise.props({
...order,
date: order.date,
item: getItem(order.item),
payments,
paymentMethod: getPaymentMethod(order.paymentMethod),
user: getUser(order.user),
});
});
}
// style 3
function asynchronouslyConstructTransformedObject(order) {
return Promise.try(() => {
const payments = Promise.map(order.payments, paymentObject => Promise.props({
payment: getPayment(paymentObject.payment),
amountCents: paymentObject.amountCents,
states: Promise.map(paymentObject.states, state => getState(state)),
}));
return Promise.props({
...order,
date: order.date,
item: getItem(order.item),
payments,
paymentMethod: getPaymentMethod(order.paymentMethod),
user: getUser(order.user),
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment