The fromEventPattern function in the rxjs library creates an Observable from a set of callback functions, one that adds an event listener and another that removes it, similarly to how the addListener and removeListener API works. Here is an example of how to use it:
index.tsx696 chars21 linesIn this example, we create an emitter object with addListener and removeListener methods that listen for and remove event listeners from the document object. We then pass those functions to fromEventPattern, along with the name of the event we want to listen for ('mousemove'), and this returns an Observable that we can subscribe to in order to listen for events. When an event is emitted, the event object is passed to the subscriber's next callback.
gistlibby LogSnag