1 00:00:00,550 --> 00:00:08,740 While working with actions, a better way we can set them up is by saving them in variable and then 2 00:00:08,740 --> 00:00:12,570 using the variable instead and why we would want to do that one. 3 00:00:12,670 --> 00:00:18,370 All this, of course, we are dispatching our actions, but since they're strong, it's very easy to 4 00:00:18,370 --> 00:00:19,340 make a typo. 5 00:00:19,780 --> 00:00:25,690 For example, if I'm going to copy and paste two more times and if everything is correct, of course 6 00:00:25,690 --> 00:00:27,860 my value should be for. 7 00:00:28,210 --> 00:00:32,990 But what if I make a typo, for example, or make a typo? 8 00:00:33,310 --> 00:00:39,720 Now, of course, the action does not match and my value instead of four is to see what happens. 9 00:00:39,730 --> 00:00:41,980 I dispatch this action two times. 10 00:00:42,130 --> 00:00:50,830 However, in my producer, none of the statements match to whatever action I dispatched and it's very 11 00:00:50,830 --> 00:00:54,280 hard to find it because we also don't get the error correct. 12 00:00:54,670 --> 00:01:00,880 If we just have a string, we had a typo and then we can spend all day looking for the bug, even though 13 00:01:00,880 --> 00:01:03,760 it's just as simple as missing one letter. 14 00:01:04,150 --> 00:01:08,590 And that's why a better setup is setting up actions as variables. 15 00:01:08,830 --> 00:01:13,240 How that would look like, again, common practice is using the uppercase. 16 00:01:13,420 --> 00:01:16,390 So, for example, we have what for actions? 17 00:01:16,390 --> 00:01:16,740 Correct. 18 00:01:16,990 --> 00:01:21,490 So in my case, I'm going to go with the crease, let me go with uppercase in this case. 19 00:01:21,790 --> 00:01:27,480 So I'm going to decrease and that will be equal to my string value of decrease as well. 20 00:01:27,790 --> 00:01:31,390 So let me just read time that I have my decrease. 21 00:01:31,660 --> 00:01:38,920 And now instead of using the string everywhere where I set up that action type, instead I'm going to 22 00:01:38,920 --> 00:01:40,810 use my decrease variable. 23 00:01:41,080 --> 00:01:47,050 So decrease in reducer and the same goes for my dispatch instead of string. 24 00:01:47,380 --> 00:01:49,510 I'm just going to keep it as a variable. 25 00:01:49,750 --> 00:01:55,870 And in this case, if I have a typo right away, I'm going to have a big fat error. 26 00:01:56,080 --> 00:02:02,530 For example, notice we have the error where it says, you know what, you haven't defined this variable. 27 00:02:02,710 --> 00:02:07,630 And of course, I haven't defined it because the name is decrease, not the one that I have here. 28 00:02:07,960 --> 00:02:14,070 So that's why it is much more better setup if we have our actions as a variables. 29 00:02:14,230 --> 00:02:17,920 And in those variables, we hold the value for our string. 30 00:02:18,220 --> 00:02:25,150 And then since usually you have more than just one action, a common practice is setting up a separate 31 00:02:25,150 --> 00:02:26,230 file altogether. 32 00:02:26,500 --> 00:02:29,470 So where I have the source, I'm going to create a new file. 33 00:02:29,770 --> 00:02:33,510 And you guessed it, I'm going to call this actions SJS. 34 00:02:33,850 --> 00:02:37,720 Now, in the actions Jass, I would want to set up my variables. 35 00:02:37,960 --> 00:02:39,880 Of course I would want to export them. 36 00:02:40,150 --> 00:02:44,890 So in Apgar's and then later in the reducers file, I can import them. 37 00:02:45,100 --> 00:02:47,410 So one by one we're going to go with export. 38 00:02:47,620 --> 00:02:52,480 And of course it's going to be named import, not a default one, since there's going to be multiple 39 00:02:52,480 --> 00:02:54,820 actions and now we're just going to name them. 40 00:02:55,090 --> 00:03:00,120 And I'm right away going to write my actions for the application we're going to build. 41 00:03:00,460 --> 00:03:06,370 So not for just testing out the redox, but in fact all the actions we're going to use later on. 42 00:03:06,650 --> 00:03:10,600 That's why some of them we're not going to be using, of course, in reducer. 43 00:03:10,810 --> 00:03:13,000 But I would want to set them up right away. 44 00:03:13,300 --> 00:03:14,800 So I'm going to go decrease. 45 00:03:16,010 --> 00:03:19,710 Decrease and that is going to be equal to my decreased strength. 46 00:03:20,150 --> 00:03:24,470 Then let me copy and paste five times because I would want to have six values. 47 00:03:24,780 --> 00:03:30,020 I'm going to use Command D to delete all of them like so. 48 00:03:30,260 --> 00:03:32,050 And then one by one, let's set them up. 49 00:03:32,180 --> 00:03:33,590 So I'm going to use two cursors. 50 00:03:33,590 --> 00:03:36,260 In this case, I'm going to go with increase. 51 00:03:36,810 --> 00:03:39,860 The next one is remove. 52 00:03:40,190 --> 00:03:44,840 So that is responsible for removing a single item that is going to be a fraction. 53 00:03:45,320 --> 00:03:48,140 After that, we're going to have action to clear the whole card. 54 00:03:48,260 --> 00:03:53,630 So clear cut after that we're going to have Gaturro and get the amount. 55 00:03:54,230 --> 00:03:55,920 So get total. 56 00:03:56,340 --> 00:04:02,570 Now, I do need to place here the underscore in between and then also I'm going to have the same thing 57 00:04:02,780 --> 00:04:03,800 for Garamond. 58 00:04:04,870 --> 00:04:06,580 Reselected get. 59 00:04:08,290 --> 00:04:15,490 And we can say it a lot works well, and now, of course, if we are exporting, we also need to import 60 00:04:15,490 --> 00:04:18,040 in our armchairs for the time being. 61 00:04:18,040 --> 00:04:21,570 We're not going to import all of them because, again, we're just testing out. 62 00:04:21,820 --> 00:04:25,030 So I would just want to import decrease and increase. 63 00:04:25,210 --> 00:04:32,140 And in fact, I will remove the other to the reset and change name since again, this is just for practicing 64 00:04:32,140 --> 00:04:32,620 redox. 65 00:04:32,800 --> 00:04:35,500 It's not going to be implemented in our application. 66 00:04:35,810 --> 00:04:39,310 So let me delete, of course, my two statements. 67 00:04:39,670 --> 00:04:48,250 Then I also would want to only use decrease and increase like so, so change name and reset will go. 68 00:04:48,550 --> 00:04:50,920 Of course we are going to change this to a variable. 69 00:04:51,190 --> 00:04:54,160 Same here, but we do need to import it first. 70 00:04:54,550 --> 00:05:01,780 So maybe right after store I'm going to close my sidebar and then instead of all caps, I'm going to 71 00:05:01,780 --> 00:05:10,660 go with import and then I'm importing decrease and then increase and not increase, but increase. 72 00:05:10,900 --> 00:05:13,360 Weichsel, coming from the actions. 73 00:05:13,810 --> 00:05:16,950 And then of course, I do need to reference the file. 74 00:05:17,200 --> 00:05:20,170 So from DOT and then actions. 75 00:05:20,410 --> 00:05:24,450 And once we have imported, then of course we're going to send this to a variable. 76 00:05:24,760 --> 00:05:29,080 Now, I'm not going to use the local variable, even though, again, technically you could set this 77 00:05:29,080 --> 00:05:29,710 up this way. 78 00:05:30,010 --> 00:05:34,690 But again, what happens with actions just it just frees up the space. 79 00:05:34,930 --> 00:05:41,590 So you're not clogging up your files that way, because in most cases there's more than just one action. 80 00:05:41,800 --> 00:05:47,950 So I'm going to remove the decrease my local variable and instead of increased string, I'm going to 81 00:05:47,950 --> 00:05:50,470 set this up as increased variable. 82 00:05:50,740 --> 00:05:56,320 And the same thing, of course, I'm going to do here in the bottom where I'm dispatching the action 83 00:05:56,680 --> 00:06:02,620 instead of using straight up string, we're going to use a variable that holds that string value. 84 00:06:02,890 --> 00:06:06,070 And that way, of course, we can have less errors. 85 00:06:06,460 --> 00:06:13,800 Let me delete all these strings like so and then I'm just going to reference my increased variable the 86 00:06:13,810 --> 00:06:17,070 moment I served notice I have the value of three. 87 00:06:17,350 --> 00:06:21,130 So the first one I decrease by one and then I increase four times. 88 00:06:21,380 --> 00:06:22,970 That's the reason why I have three. 89 00:06:23,200 --> 00:06:28,480 And again, the reason why you would want to set up your actions as a variable is because there is a 90 00:06:28,480 --> 00:06:33,910 very easy to make a typo, especially if you're typing, I don't know, twenty thousand times throughout 91 00:06:33,910 --> 00:06:34,630 your application. 92 00:06:34,870 --> 00:06:40,030 But if you set it up as a variable and if you have the wrong reference, you're right away are going 93 00:06:40,030 --> 00:06:40,690 to get there. 94 00:06:41,020 --> 00:06:44,200 And as always, there is a bug as I'm typing. 95 00:06:44,410 --> 00:06:48,490 It should be simple remove instead of the gibberish that I had here before.