Skip to content

Instantly share code, notes, and snippets.

@Killavus
Last active April 26, 2019 10:29
Show Gist options
  • Select an option

  • Save Killavus/3dedfb89dbe4cc53ee364ce4b1951dbb to your computer and use it in GitHub Desktop.

Select an option

Save Killavus/3dedfb89dbe4cc53ee364ce4b1951dbb to your computer and use it in GitHub Desktop.
Ports example in hexagonal architecture
const ProcessingCustomerPorts = (useCase, userInterface, router, eventBus, errorHandler) => {
// inbound messages - here event bus approach is used.
eventBus.on('addItemToCart', item => {
useCase.addItemToCart(item);
});
eventBus.on('cartLoaded', items => {
items.forEach(item => {
useCase.addItemToCart(item);
});
});
// outbound messages - passed directly to the use case.
// Can use event bus publishing as well on the use case side.
return {
cartErrorHappened(userMessage) {
errorHandler.notify(errorHandler.USER_ERROR, userMessage);
},
cartItemAdded(cartItems, addedItem) {
userInterface.updateCart(cartItems);
},
cartItemsConfirmed() {
router.proceedToCheckout();
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment