At the moment, our initial store is super nice and cute, I mean, one property with a no value.
Come on, what could be better than that?
In reality, though, chances are your applications that will be more complicated than that.
So what to do if we have more properties or so, I guess.
Let's take a look at the problem that we're going to have if we're going to add more properties, but
still keep our functionality exactly the way it is.
So I'm going to go with name property again, very, very original.
And I'm going to go with John.
So I say it, OK?
At the moment nothing is happening.
But I can see down here where I have get state that for some reason John is missing.
So why is the John missing?
I would do a little bit of investigation.
So I have my first one.
That is, of course, my console log that is coming from reducer.
And I can see that I'm getting the whole object and have count zero and the name is equal to the John.
But once I return after the first action, is that matched, which in my case is going to be decreased,
you'll see that John is going to go bananas.
So let me check the first one.
That is, of course, where I'm still getting the old state.
So that doesn't count.
This is the first time where I'm having the crease.
But after I'm done with my first decrease, of course, count as a negative one and John is simply missing.
So why is John missing?
Well, let's think about it.
We have the object.
I'm returning the property with a count and then I'm just checking for my state.
So we're done here.
Well, John is nowhere to be found.
That's why we don't have it in our results.
And what will be the solution?
Well, prior to E six, we could use the object DOT assigned.
So essentially what we would want to do is copy the properties from the old object and then only the
ones that we would want to change those ones we would set a new value for.
But the ones that we would want to keep the same, well, we wouldn't touch them.
Now, like I said, prior to US six, we would use object dot assign.
However, with the arrival of year six, we have a easier way and that is object spread printer.
So let me delete it.
And then the way objects per operator works is we are still going to return a new object.
So that still stays the same.
But then if we type.
Dot, dot, dot and then state what effectively we're doing, we're copying pasting all the values from
my old state.
No, I'm not mutating.
I'm just copying, pasting the values.
So now I have access to all the old state values.
Now the thing is, if I type here which property I want to change, for example, I know I have the
account correct.
And if I would want to affect the account, I just need to type count property and now I'm going to
override that and set it to a new value.
So what is going to be my new value?
Well, I'm going to set my account to be equal to state dot count minus one, so that still stays exactly
the same.
The difference here in this case, since I have multiple properties now, instead of just creating a
new property and then using the old value, now I'm actually copying pasting the properties from the
old state as well.
And what I'm talking about, the other properties, the ones that I'm not changing.
So now in this case, let me change this around for all of them.
So like I said, I just need to add here that the objects per operator, so DataDot and then old state,
so just spread out all the state properties that are coming from the old state and then return the count
one change.
And then of course I would want to do the same one for a reset as well, because I'm still looking for
Ajan.
So let me go down to that then state comma and now I'm overriding the account, let me say it.
And now at the very bottom I still have my job.
So this would be the syntax if our initial store or initial state has more values and just to this home
we're going to create one for the name just so we can see what happens.
If we're changing the value for money now instead of round, I'm going to go with change and name change
name.
Now, again, I'm going to copy and paste Mexico and somewhere here I'm going to check for that action
type.
So maybe right after that I'm going to say if action that type is equal to change name, well, then
I would want to change it to.
How do we do that again?
We return a new object, I'm going to spread out the properties from the old state, so essentially
I'm going to copy and paste them.
And then instead of changing the count, I'm going to change my name to Bob or maybe Bubble.
That's also fine.
So now in the bottom, the count is two and the name is Bulbul or whatever.
You place it over here.
So, again, if we have multiple properties in our state, then we cannot just simply return a new object
with just one property that we would want to change effectively.
We need to make sure that we get all the properties and then only the ones that we would want overwrite
or give it a new value.
Those are the ones that we're adding here.
Now, of course, we're not limited to just changing one property.
For example, if I have decrease, I could also change my name here, since that is the second property.
Keep in mind, if you're going to try to change some kind of property, that is not only the object,
of course, that will not make sense.
But since I know that I have two properties, I have the count and I have the name, for example, here
I'm going to write honor now again, if I'm going to check the third.
So, of course, that is after my first decrease.
I'm going to see that name is right now.
So the count is negative one.
But then I set up my name to be.