1
00:00:00,180 --> 00:00:06,480
All right, and once we have a general concept behind events as well as event driven programming, now

2
00:00:06,480 --> 00:00:09,030
let's set up our own events in Noad.

3
00:00:09,330 --> 00:00:11,940
And the way we do that, we come up with a variable.

4
00:00:12,180 --> 00:00:20,550
And typically this name is event a matter, because what we're getting back is the class and we require

5
00:00:20,730 --> 00:00:22,170
the event module.

6
00:00:22,470 --> 00:00:27,870
So require a module and we assign it to a variable, which essentially is a class.

7
00:00:28,080 --> 00:00:32,460
And again, a common practice is calling this event a matter.

8
00:00:32,790 --> 00:00:34,860
And at this point you have two options.

9
00:00:34,860 --> 00:00:42,450
If you want to create something custom, you will need to extend the class, or if you simply want to

10
00:00:42,990 --> 00:00:47,870
omit an event as well as listen for it, then you can just create the instance.

11
00:00:47,870 --> 00:00:48,360
So go.

12
00:00:48,360 --> 00:00:52,590
The second route will go with const and then whatever name you would want.

13
00:00:52,600 --> 00:01:00,120
In my case, I'm just going to call this custom matter like so, and I'll sign it to new ammeter.

14
00:01:00,330 --> 00:01:05,590
So event matter or however you call this variable and we just need to invoke it.

15
00:01:05,610 --> 00:01:09,260
So now we have the instance of our class.

16
00:01:09,480 --> 00:01:10,870
So essentially we have the object.

17
00:01:11,190 --> 00:01:16,180
Now there are many methods in this object or two that we're interested in.

18
00:01:16,200 --> 00:01:22,470
Most are on an aim and so on will listen for a specific amount.

19
00:01:22,770 --> 00:01:26,400
And then I met, of course, will admit that event.

20
00:01:26,880 --> 00:01:33,190
And the way we set it up, we go with custom matter or whatever name you used, and then we go with

21
00:01:33,210 --> 00:01:41,670
on and at the very basic setup in the on method, we just pass in the string when we say the name of

22
00:01:41,670 --> 00:01:42,300
the event.

23
00:01:42,780 --> 00:01:45,810
In my case, I'll name my one response.

24
00:01:46,170 --> 00:01:50,950
And then of course, once I have described to it, I also would want to pass in the callback function.

25
00:01:51,300 --> 00:01:56,820
So essentially when this event takes place, well then I would want to do something.

26
00:01:57,180 --> 00:02:04,860
In my case, I'll just go with console log and or simply say they received or I'll place this one in

27
00:02:04,860 --> 00:02:06,810
the template strings and you'll see in a second why.

28
00:02:06,810 --> 00:02:12,980
So I'll go with data received and eventually there's going to be some more data.

29
00:02:13,380 --> 00:02:20,190
And of course, once we have subscribed to the specific event, now one, I met it and the way we do

30
00:02:20,190 --> 00:02:22,440
that, we just go custom matter.

31
00:02:22,770 --> 00:02:26,580
And of course, the method is surprise, surprise element.

32
00:02:26,970 --> 00:02:30,790
And of course, at this point, these strings need to match.

33
00:02:30,990 --> 00:02:39,210
So if I'm omitting the response event and just say here response and what you'll see in the console

34
00:02:39,480 --> 00:02:41,830
is wherever you have in callback.

35
00:02:42,240 --> 00:02:48,690
So of course, in my case, I have a blog that data received and then once I ran it, I have data received

36
00:02:48,960 --> 00:02:49,760
in a console.

37
00:02:49,860 --> 00:02:53,830
So that's the most basic setup when it comes to events.

38
00:02:53,850 --> 00:02:59,220
Again, we create an instance from the class that we get back from the events module.

39
00:02:59,460 --> 00:03:01,830
And then we have two methods.

40
00:03:01,830 --> 00:03:08,420
We have our own method as well as the method and in the method we pass in the string.

41
00:03:08,670 --> 00:03:12,790
So that's going to be the name of the event as well as the callback function.

42
00:03:13,290 --> 00:03:20,990
So once this event takes place, then of course we would to do something and I guess we'll just cancel

43
00:03:21,000 --> 00:03:22,650
log data received.

44
00:03:23,010 --> 00:03:28,590
And then once we have subscribed to this event, then of course we need to omit it.

45
00:03:28,950 --> 00:03:32,900
And the way we do that, we just go with whatever the name is.

46
00:03:32,910 --> 00:03:37,560
In my case, custom matter then and method, and then we pass.

47
00:03:37,560 --> 00:03:42,930
And the same string that we're looking for in our case, of course, responds.

48
00:03:43,260 --> 00:03:49,500
And then the moment we do that, we, of course, have whatever is in the callback function, which

49
00:03:49,500 --> 00:03:53,610
is of course, of course, is just a simple log data received.

