Last active
February 11, 2022 05:41
-
-
Save wirelessr/4e0032eb3beaca927bf864aec21bc53a 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
const events = require('events'); | |
const emitter = new events.EventEmitter(); | |
emitter.on('purchased', function(user, total) { | |
if (total >= 1000) { | |
giveCoupon(cart.user, total); | |
} | |
}); | |
emitter.on('purchased', function(user, total) { | |
if (ok && total >= 5000) { | |
lottery(cart.user, total); | |
} | |
}); | |
function purchase(cart) { | |
const total = 0; | |
for (let item of cart.items) { | |
total += item.price; | |
} | |
const ok = payByCreditCard(cart.user, total); | |
if (ok) { | |
emitter.emit('purchased', cart.user, total); | |
} | |
return ok; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment