Building custom events
Sometimes we need to make two or more entities of our application communicate with each other, that are not related. For example, we want to keep our cart independent of the application. We can create custom events to update it from the outside and the cart will react to this event; applying the business logic that is required.
We can split the event in two different events: the click and the action. So when we click on the up arrow to add a product, we fire a new custom event that handles the addition of a new unit, and the same to remove it. This give us more information about what is happening in our application, and we realize that a general meaning event such as click just gets the data and sends it to a more specialized ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access