Created
December 16, 2016 14:09
-
-
Save alextes/a8758f5764195fa883d6cd4a9c18f1a2 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
// 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