1 00:00:00,360 --> 00:00:06,750 OK, once our app is working, I would also like to cover some other redox concepts, more specifically 2 00:00:06,960 --> 00:00:10,120 reduce their default state action creators. 3 00:00:10,560 --> 00:00:17,040 But before we do that, I would like to refactor our reducer a bit, because while I think it's OK to 4 00:00:17,040 --> 00:00:22,950 copy and paste some code around while we're getting our feet wet with Radix, it's not very practical 5 00:00:22,950 --> 00:00:23,940 in the long run. 6 00:00:24,300 --> 00:00:26,310 Now, the following two videos are optional. 7 00:00:26,520 --> 00:00:32,610 So if you're happy with the code, feel free to kick back and relax, since the functionality of our 8 00:00:32,610 --> 00:00:34,560 app will not change. 9 00:00:34,890 --> 00:00:42,270 And I think the biggest offender is the decrease action because essentially I copied my remote functionality 10 00:00:42,540 --> 00:00:49,800 and also it is very similar to my increase and we'll start by removing the remove functionality. 11 00:00:50,070 --> 00:00:56,060 So instead of checking that in our juicer, whether the amount is one, I can do it also in the correct 12 00:00:56,070 --> 00:00:56,460 item. 13 00:00:56,730 --> 00:00:58,770 So now we have our button, correct? 14 00:00:58,770 --> 00:01:01,310 We have our decrease button. 15 00:01:01,590 --> 00:01:05,190 And in this case, I'm returning my decrease function. 16 00:01:05,370 --> 00:01:05,870 Correct. 17 00:01:05,880 --> 00:01:07,340 I have my decrease prob. 18 00:01:07,590 --> 00:01:10,980 That is the function and I'm just returning once I click on the crease. 19 00:01:11,370 --> 00:01:16,050 And I think a better option would be actually checking what is the amount. 20 00:01:16,260 --> 00:01:22,710 So if the amount is one then we will return, remove functionality, so we'll just remove the actual 21 00:01:22,710 --> 00:01:25,600 item or if the amount is bigger than one. 22 00:01:25,930 --> 00:01:29,130 Then of course we will still return decrease function. 23 00:01:29,400 --> 00:01:33,150 And what that allows us to do is introduce her. 24 00:01:33,360 --> 00:01:40,020 I don't need to check Portimao so that way I don't need to copy and paste my remove functionality and 25 00:01:40,020 --> 00:01:43,410 then deletions that I would want to make my first if statement. 26 00:01:43,630 --> 00:01:47,840 And also since I don't have the if statement, of course I also don't need else. 27 00:01:48,180 --> 00:01:50,280 So let me delete line 13. 28 00:01:50,280 --> 00:01:56,460 In my case, of course, maybe in your case the numbers are different, but just delete, delete also 29 00:01:56,460 --> 00:01:58,290 the closing curly brace. 30 00:01:58,560 --> 00:02:05,370 And since I wouldn't want my statement and instead of setting it equal to an empty array, well, let's 31 00:02:05,370 --> 00:02:14,280 just keep on deleting and online right away, we will set our timecard equal to a state court like so 32 00:02:14,460 --> 00:02:15,220 let's say it. 33 00:02:15,420 --> 00:02:19,110 And now, of course, we don't have the functionality of removing the item. 34 00:02:19,320 --> 00:02:23,340 So you'll notice as I'm decreasing, I'm going to go negative. 35 00:02:23,550 --> 00:02:27,210 Now, of course, the way we would fix that is in the car item. 36 00:02:27,390 --> 00:02:34,170 Like I said, we will check if the item amount will be equal to one, then of course we will return 37 00:02:34,170 --> 00:02:36,630 and run effectively promote function. 38 00:02:36,870 --> 00:02:41,070 Of course, if it's not equal to one, then we will just decrease. 39 00:02:41,340 --> 00:02:43,860 Now, in this case, I do need to set up my curly braces. 40 00:02:44,370 --> 00:02:45,960 That will be my start. 41 00:02:46,320 --> 00:02:48,960 And then of course, I'm not just returning the crease. 42 00:02:49,200 --> 00:02:50,910 I need to set up the IF statement. 43 00:02:51,240 --> 00:02:54,570 So I'm going to go with if now I still have the access to amount. 44 00:02:54,610 --> 00:03:01,110 Remember, it is still our prop and I can just check if amount is equal to one. 45 00:03:01,380 --> 00:03:05,490 Then like I said, we will return a remote function. 46 00:03:05,910 --> 00:03:09,090 So let's go remove and walk to function. 47 00:03:09,310 --> 00:03:15,840 Or if the amount is not equal to one, which would be all the other cases, then of course I will return 48 00:03:15,840 --> 00:03:16,500 the decrease. 49 00:03:16,500 --> 00:03:18,540 So let me move it in the else. 50 00:03:18,900 --> 00:03:19,830 Let's save that. 51 00:03:19,830 --> 00:03:24,090 And now once we refresh the application, you'll notice that I can still increase. 52 00:03:24,090 --> 00:03:25,770 Of course I can still decrease. 53 00:03:25,950 --> 00:03:30,420 But the moment my amount will be equal to one, I'm just going to remove the item. 54 00:03:30,690 --> 00:03:35,490 So like I said, still the same functionality or currently in the reducer. 55 00:03:35,730 --> 00:03:42,420 I'm not repeating myself by copying pasting the functionality from the removal action.