OK, once our app is working, I would also like to cover some other redox concepts, more specifically
reduce their default state action creators.
But before we do that, I would like to refactor our reducer a bit, because while I think it's OK to
copy and paste some code around while we're getting our feet wet with Radix, it's not very practical
in the long run.
Now, the following two videos are optional.
So if you're happy with the code, feel free to kick back and relax, since the functionality of our
app will not change.
And I think the biggest offender is the decrease action because essentially I copied my remote functionality
and also it is very similar to my increase and we'll start by removing the remove functionality.
So instead of checking that in our juicer, whether the amount is one, I can do it also in the correct
item.
So now we have our button, correct?
We have our decrease button.
And in this case, I'm returning my decrease function.
Correct.
I have my decrease prob.
That is the function and I'm just returning once I click on the crease.
And I think a better option would be actually checking what is the amount.
So if the amount is one then we will return, remove functionality, so we'll just remove the actual
item or if the amount is bigger than one.
Then of course we will still return decrease function.
And what that allows us to do is introduce her.
I don't need to check Portimao so that way I don't need to copy and paste my remove functionality and
then deletions that I would want to make my first if statement.
And also since I don't have the if statement, of course I also don't need else.
So let me delete line 13.
In my case, of course, maybe in your case the numbers are different, but just delete, delete also
the closing curly brace.
And since I wouldn't want my statement and instead of setting it equal to an empty array, well, let's
just keep on deleting and online right away, we will set our timecard equal to a state court like so
let's say it.
And now, of course, we don't have the functionality of removing the item.
So you'll notice as I'm decreasing, I'm going to go negative.
Now, of course, the way we would fix that is in the car item.
Like I said, we will check if the item amount will be equal to one, then of course we will return
and run effectively promote function.
Of course, if it's not equal to one, then we will just decrease.
Now, in this case, I do need to set up my curly braces.
That will be my start.
And then of course, I'm not just returning the crease.
I need to set up the IF statement.
So I'm going to go with if now I still have the access to amount.
Remember, it is still our prop and I can just check if amount is equal to one.
Then like I said, we will return a remote function.
So let's go remove and walk to function.
Or if the amount is not equal to one, which would be all the other cases, then of course I will return
the decrease.
So let me move it in the else.
Let's save that.
And now once we refresh the application, you'll notice that I can still increase.
Of course I can still decrease.
But the moment my amount will be equal to one, I'm just going to remove the item.
So like I said, still the same functionality or currently in the reducer.
I'm not repeating myself by copying pasting the functionality from the removal action.