In this lecture, we are going to explore a creation operator for creating observables out of events.
It's highly likely you will need to work with DOM events.
The from event operator will create an observable from an event.
Let's try using these from event operator on the import statement.
Swap the interval operator with the from event operator.
Next, we need to perform the same swap for the variable.
The from event operator has two arguments.
The first argument is the targets the target refers to the elements in the document the observable should
watch.
We're going to keep this example simple.
We will listen for events on the document object.
The second argument is the name of the event.
Every event in JavaScript is supported.
Let's listen for a click event.
On the page, we can click on the document to Imette, the event.
The observer will receive the event object with every click by using the from event operator.
We can create an observable out of an event.
Each subscription will be given its own handler every time we call the subscribed function.
A new event listener is created for each subscription.
This behavior allows for other subscriptions to remain functional and uninterrupted.
The operator will handle this process for us as usual.
The observable will listen for clicky events until the user closes the app.
If we don't need to listen for events, we should unsubscribe from the observable.
Otherwise, we may experience a memory leak.
The from event operator will not automatically stop listening for events in a future lecture.
We will explore how to complete an observable with operators.
For now, we must manually unsubscribe from an observable with the unsubscribe function in the next
lecture.
We are going to explore some more creation operators.