Created
April 16, 2016 17:34
-
-
Save Killavus/7418e505e45ddc7d154c6b06a43087cc to your computer and use it in GitHub Desktop.
A simple use case in hexagonal architecture.
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 MAX_TOTAL_ITEMS_IN_CART = 10; | |
const ProcessingCustomerCart = ports => { | |
let cartItems = []; | |
return { | |
addItemToCart(item) { | |
const cartItemsWithAddedItem = cartItems.concat([item]); | |
if (MAX_TOTAL_ITEMS_IN_CART < cartItemsWithAddedItem.length) { | |
ports.cartErrorHappened("Too many items in cart. Please proceed to checkout."); | |
} else { | |
cartItems = cartItemsWithAddedItem; | |
ports.cartItemAdded(cartItemsWithAddedItem, item); | |
} | |
}, | |
cartItemsConfirmed() { | |
ports.cartItemsConfirmed(cartItems); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment