Last active
April 26, 2019 10:29
-
-
Save Killavus/3dedfb89dbe4cc53ee364ce4b1951dbb to your computer and use it in GitHub Desktop.
Ports example in hexagonal architecture
This file contains hidden or 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 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