Event-Driven Programming Patterns
Event-driven programming in JavaScript is very widespread and is the only way to handle certain scenarios. Maintaining performance and security around event listeners is of paramount importance. Mismanaged event listeners have been a historical source of bugs and critical performance issues; we’ll address this via the event delegation pattern. Secure messaging between frames and contexts has always been crucial in the context of payments. More recently, new primitives are being added to the web platform and JavaScript that exposes an event/messaging interface for maintaining isolation between contexts.
In this chapter, we’ll cover the following topics:
- Implementing event delegation
- Using the
postMessage
interface to communicate across contexts with an example of a payment iframe - Common event listener antipatterns and how to remediate them
At the end of this chapter, you’ll have learned how to use advanced...