Last active
September 13, 2017 14:09
-
-
Save AlphaGit/9e3a03cac580a7a0020c64f7f7d2ebaa to your computer and use it in GitHub Desktop.
Good code / bad code: bad code
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
function checkOutCart(session, cb) { // this is the code that executes on checkout | |
getUserInfo(session.userId, function(err, user) { // it'll get the user information | |
if (err) { return cb(err); } // if it has any error, it will call back with it | |
if (user.hasDiscountedProfile) { // if the user has a profile for discounts | |
retrieveDiscount(user.profileId, function(err, discAmt) { // it will retrieve that discount | |
if (err) { return cb(err); } // on error, it aborts the operation | |
session.cart.addDiscount(discAmt); // adds the discount to the cart | |
getPaymentScreenConfig(function(err, payScrCfg) { // it retrieves the configuration from the payment screen | |
if (err) { return cb(err); } // on error, it aborts | |
cb(null, new PaymentScreen(payScrCfg, session.cart)); // creates a payment screen and returns it | |
}); // something finished... getPaymentsScreenConfig | |
}); // something finished... what was it? *looks* ah, getUserInfo. No! retrieveDiscount. I think. | |
} else { // if not... if not what? | |
if (err) { return cb(err); } // if error... from what? operation aborted. | |
getPaymentScreenConfig(function(err, payScrCfg) { // it gets the payment screen configuration... again? | |
cb(new PaymentScreen(payScrCfg, session.cart)); // returns the payment screen | |
}); // finish get payment screen | |
} // else section finished | |
}); // something else finished here | |
trackActivity(session, ACTIONS.CHECKED_OUT); // tracks activity... is this in the right place? | |
} // everything finished... what was wrong with this in the first place? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment