We are building a High-Frequency Trading Terminal. The interface has hundreds of buttons, inputs, and real-time data toggles. Using raw addEventListener across the app has led to memory leaks because developers frequently forget to call removeEventListener when components are destroyed.
The Task: Implement a simplified Observable.fromEvent utility. This utility must encapsulate the event listener logic so that the lifecycle of the event is tied directly to the subscription. When a user subscribes, the listener is attached; when they unsubscribe, it is removed. How do you ensure this is memory-safe and supports multiple independent observers?