Skip to content

Instantly share code, notes, and snippets.

@Killavus
Created April 16, 2016 17:34
Show Gist options
  • Save Killavus/7418e505e45ddc7d154c6b06a43087cc to your computer and use it in GitHub Desktop.
Save Killavus/7418e505e45ddc7d154c6b06a43087cc to your computer and use it in GitHub Desktop.
A simple use case in hexagonal architecture.
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