1 00:00:00,120 --> 00:00:05,610 And one more interesting Riddick's concept that I would want to show you is how we can create action 2 00:00:05,610 --> 00:00:06,280 creators. 3 00:00:06,690 --> 00:00:10,620 Now, it sounds way more complicated than it really is. 4 00:00:10,860 --> 00:00:18,330 And the general idea behind action creators is following where notice when we're setting up our functions. 5 00:00:18,330 --> 00:00:18,720 Correct. 6 00:00:19,020 --> 00:00:24,810 We have this dispatch and then, of course, we do need to have our actions object and then we need 7 00:00:24,810 --> 00:00:25,860 to pass in time. 8 00:00:26,220 --> 00:00:31,560 And it is fine in our small application because, of course, we're just despatching, for example, 9 00:00:31,740 --> 00:00:34,200 the removal action one time. 10 00:00:34,470 --> 00:00:40,710 But then you can imagine as your application grows and you need to rewrite this multiple times in some 11 00:00:40,710 --> 00:00:44,900 way, you're asking for trouble because you might introduce the bug. 12 00:00:45,030 --> 00:00:52,860 And the way action creators work is we set up the function that always, always returns our particular 13 00:00:52,860 --> 00:00:53,190 type. 14 00:00:53,370 --> 00:01:00,160 And then optionally if we want to pass some kind of parameters in function, of course we can do that. 15 00:01:00,420 --> 00:01:03,720 Now, I will not refactor all my actions again. 16 00:01:03,720 --> 00:01:04,710 That would be an oracle. 17 00:01:04,960 --> 00:01:11,400 However, we will rewrite our remove action using the action creator just so you can see the benefit 18 00:01:11,400 --> 00:01:11,830 of that. 19 00:01:12,060 --> 00:01:14,220 And like I said, it would be a function. 20 00:01:14,250 --> 00:01:18,420 So instead of passing it manually, our actions object with the type. 21 00:01:18,630 --> 00:01:21,710 We're just going to set up a function that does that for us. 22 00:01:21,960 --> 00:01:23,280 I'm going to go with export again. 23 00:01:23,280 --> 00:01:27,690 We would need to export it since we'll use it instead of a plan of action. 24 00:01:27,900 --> 00:01:33,090 And then, as I always call it, whatever you want, I'm going to go remove item. 25 00:01:33,210 --> 00:01:35,310 And then, like I said, it will be a function. 26 00:01:35,340 --> 00:01:37,800 Let me set this up as a empty function. 27 00:01:37,920 --> 00:01:44,010 And then, like I already previously mentioned, the whole point of this action, creator, is to always 28 00:01:44,040 --> 00:01:48,390 return a proper action with a proper type. 29 00:01:48,720 --> 00:01:55,560 So in our case, since I'm setting up action creator for removal, of course I will return the action 30 00:01:55,560 --> 00:01:58,340 object with a type of remove. 31 00:01:58,680 --> 00:02:00,000 So I'm going to return. 32 00:02:00,270 --> 00:02:02,370 Then I'm returning my object type. 33 00:02:02,370 --> 00:02:05,250 Yes, you guessed it will be removed. 34 00:02:05,500 --> 00:02:09,050 And then remember for remove, we still needed the payload. 35 00:02:09,210 --> 00:02:10,410 So that doesn't change. 36 00:02:10,410 --> 00:02:12,600 I still need to pass here the payload. 37 00:02:12,830 --> 00:02:17,220 In my case, I'm going to send this up as an object and then I'm passing in the area. 38 00:02:17,610 --> 00:02:20,880 And now probably the question is, well, where are we going to get this? 39 00:02:21,510 --> 00:02:23,100 Well, we're setting this up as a function. 40 00:02:23,110 --> 00:02:23,510 Correct. 41 00:02:23,820 --> 00:02:27,300 So I'm just going to say, alright, so just pass here as an argument. 42 00:02:27,300 --> 00:02:34,380 My idea now I will say my actions and then of course we will navigate to Karakoram because that's where 43 00:02:34,380 --> 00:02:35,580 we're using the remove item. 44 00:02:35,850 --> 00:02:37,260 Now we do need to import it. 45 00:02:37,530 --> 00:02:39,610 So I have increased decrease and all that. 46 00:02:39,900 --> 00:02:43,590 So now I'm just going to be importing my remove item. 47 00:02:43,830 --> 00:02:44,540 OK, awesome. 48 00:02:44,760 --> 00:02:52,200 And then let's scroll down to the bottom and then replace our simple remove where we manually wrote 49 00:02:52,200 --> 00:02:58,590 or type removing all that payload and pass in at this patch our function again, it sounds way more 50 00:02:58,590 --> 00:03:00,120 complicated than it really is. 51 00:03:00,330 --> 00:03:07,650 What you're doing is you're taking out the manual labor of setting up your action objects by hand just 52 00:03:07,650 --> 00:03:09,480 by passing here, removing them. 53 00:03:09,690 --> 00:03:15,080 Now we're still getting our ID from our own props so I can pass in Mayadeen right here. 54 00:03:15,300 --> 00:03:19,010 And as you will see, the functionality will not change. 55 00:03:19,020 --> 00:03:25,260 But just imagine the scenario where you would have an application where you would need to dispatch your 56 00:03:25,260 --> 00:03:27,050 remote location 20 times. 57 00:03:27,180 --> 00:03:32,010 So which option would be easier and potentially have less bugs? 58 00:03:32,340 --> 00:03:38,970 You have a function where you just need to pass the area and you always, always will have your type 59 00:03:38,970 --> 00:03:40,740 correct equal to remove. 60 00:03:40,950 --> 00:03:43,260 And yes, you would send them up in the same file. 61 00:03:43,530 --> 00:03:44,260 Might as well. 62 00:03:44,280 --> 00:03:50,370 You have your actions so you right away can pass it or the other option would be manually again type 63 00:03:50,370 --> 00:03:52,530 increase, then payload and all that. 64 00:03:52,650 --> 00:03:58,920 And I think we have a pretty clear winner because I think it is much more easier to get our function 65 00:03:59,100 --> 00:04:02,700 and then optionally pass some kind of argument, if you would have to. 66 00:04:02,970 --> 00:04:08,700 If you don't have to, then you would always just return the correct action type. 67 00:04:09,060 --> 00:04:11,770 So that's how we can set up our action creators. 68 00:04:12,210 --> 00:04:18,180 Now, let me double check, because that would be hilarious if I'm trying to show you a better way how 69 00:04:18,180 --> 00:04:20,640 you can set up your application to avoid bugs. 70 00:04:20,640 --> 00:04:27,990 But then I would introduce bugs in my own application one to three and let it go on so we can set up 71 00:04:28,230 --> 00:04:31,560 the actual creators in our redox application.