1 00:00:00,120 --> 00:00:06,450 In this lecture, we are going to explore a creation operator for creating observables out of events. 2 00:00:06,780 --> 00:00:10,050 It's highly likely you will need to work with DOM events. 3 00:00:10,410 --> 00:00:14,680 The from event operator will create an observable from an event. 4 00:00:14,910 --> 00:00:19,770 Let's try using these from event operator on the import statement. 5 00:00:19,800 --> 00:00:23,820 Swap the interval operator with the from event operator. 6 00:00:26,310 --> 00:00:30,300 Next, we need to perform the same swap for the variable. 7 00:00:32,860 --> 00:00:36,070 The from event operator has two arguments. 8 00:00:36,340 --> 00:00:43,150 The first argument is the targets the target refers to the elements in the document the observable should 9 00:00:43,150 --> 00:00:43,690 watch. 10 00:00:43,900 --> 00:00:46,210 We're going to keep this example simple. 11 00:00:46,420 --> 00:00:49,840 We will listen for events on the document object. 12 00:00:52,430 --> 00:00:55,190 The second argument is the name of the event. 13 00:00:55,610 --> 00:00:58,130 Every event in JavaScript is supported. 14 00:00:58,430 --> 00:01:00,350 Let's listen for a click event. 15 00:01:03,040 --> 00:01:07,090 On the page, we can click on the document to Imette, the event. 16 00:01:07,450 --> 00:01:14,260 The observer will receive the event object with every click by using the from event operator. 17 00:01:14,410 --> 00:01:17,260 We can create an observable out of an event. 18 00:01:17,890 --> 00:01:23,800 Each subscription will be given its own handler every time we call the subscribed function. 19 00:01:23,980 --> 00:01:27,610 A new event listener is created for each subscription. 20 00:01:28,060 --> 00:01:33,520 This behavior allows for other subscriptions to remain functional and uninterrupted. 21 00:01:33,910 --> 00:01:38,350 The operator will handle this process for us as usual. 22 00:01:38,500 --> 00:01:43,360 The observable will listen for clicky events until the user closes the app. 23 00:01:43,720 --> 00:01:48,730 If we don't need to listen for events, we should unsubscribe from the observable. 24 00:01:49,060 --> 00:01:52,180 Otherwise, we may experience a memory leak. 25 00:01:52,600 --> 00:01:59,060 The from event operator will not automatically stop listening for events in a future lecture. 26 00:01:59,110 --> 00:02:03,310 We will explore how to complete an observable with operators. 27 00:02:03,610 --> 00:02:10,870 For now, we must manually unsubscribe from an observable with the unsubscribe function in the next 28 00:02:10,870 --> 00:02:11,500 lecture. 29 00:02:11,590 --> 00:02:15,160 We are going to explore some more creation operators.