The fromEventPattern
function in the rxjs
library creates an Observable from an event pattern. This function takes two arguments:
addHandler
: a function that takes a handler
function and attaches it to an event sourceremoveHandler
: a function that takes the handler
function and detaches it from the event sourceHere is an example of how to use the fromEventPattern
function in TypeScript:
index.ts618 chars21 lines
In this example, we create an Observable clicks$
that emits each time the user clicks on the document
. We use the fromEventPattern
function to create the Observable, passing in the addClickListener
and removeClickListener
functions. Finally, we subscribe to the clicks$
Observable to log the MouseEvent
to the console each time a click occurs.
gistlibby LogSnag