1 00:00:00,180 --> 00:00:07,010 At the moment, our initial store is super nice and cute, I mean, one property with a no value. 2 00:00:07,230 --> 00:00:09,290 Come on, what could be better than that? 3 00:00:09,690 --> 00:00:16,020 In reality, though, chances are your applications that will be more complicated than that. 4 00:00:16,410 --> 00:00:20,350 So what to do if we have more properties or so, I guess. 5 00:00:20,370 --> 00:00:25,920 Let's take a look at the problem that we're going to have if we're going to add more properties, but 6 00:00:25,920 --> 00:00:30,920 still keep our functionality exactly the way it is. 7 00:00:31,320 --> 00:00:35,520 So I'm going to go with name property again, very, very original. 8 00:00:35,730 --> 00:00:38,190 And I'm going to go with John. 9 00:00:38,550 --> 00:00:40,110 So I say it, OK? 10 00:00:40,140 --> 00:00:42,480 At the moment nothing is happening. 11 00:00:42,810 --> 00:00:48,860 But I can see down here where I have get state that for some reason John is missing. 12 00:00:49,470 --> 00:00:50,700 So why is the John missing? 13 00:00:51,130 --> 00:00:54,090 I would do a little bit of investigation. 14 00:00:54,420 --> 00:00:55,560 So I have my first one. 15 00:00:55,740 --> 00:00:59,250 That is, of course, my console log that is coming from reducer. 16 00:00:59,670 --> 00:01:04,560 And I can see that I'm getting the whole object and have count zero and the name is equal to the John. 17 00:01:05,160 --> 00:01:12,360 But once I return after the first action, is that matched, which in my case is going to be decreased, 18 00:01:12,730 --> 00:01:16,670 you'll see that John is going to go bananas. 19 00:01:16,980 --> 00:01:18,390 So let me check the first one. 20 00:01:18,510 --> 00:01:21,300 That is, of course, where I'm still getting the old state. 21 00:01:21,570 --> 00:01:22,620 So that doesn't count. 22 00:01:22,890 --> 00:01:24,900 This is the first time where I'm having the crease. 23 00:01:25,410 --> 00:01:32,700 But after I'm done with my first decrease, of course, count as a negative one and John is simply missing. 24 00:01:32,940 --> 00:01:34,200 So why is John missing? 25 00:01:34,470 --> 00:01:35,370 Well, let's think about it. 26 00:01:35,760 --> 00:01:36,570 We have the object. 27 00:01:36,900 --> 00:01:42,690 I'm returning the property with a count and then I'm just checking for my state. 28 00:01:43,020 --> 00:01:44,030 So we're done here. 29 00:01:44,550 --> 00:01:46,440 Well, John is nowhere to be found. 30 00:01:46,670 --> 00:01:48,990 That's why we don't have it in our results. 31 00:01:49,410 --> 00:01:50,820 And what will be the solution? 32 00:01:51,270 --> 00:01:56,600 Well, prior to E six, we could use the object DOT assigned. 33 00:01:56,940 --> 00:02:05,280 So essentially what we would want to do is copy the properties from the old object and then only the 34 00:02:05,280 --> 00:02:09,420 ones that we would want to change those ones we would set a new value for. 35 00:02:09,780 --> 00:02:13,730 But the ones that we would want to keep the same, well, we wouldn't touch them. 36 00:02:14,190 --> 00:02:19,680 Now, like I said, prior to US six, we would use object dot assign. 37 00:02:19,980 --> 00:02:26,970 However, with the arrival of year six, we have a easier way and that is object spread printer. 38 00:02:27,390 --> 00:02:28,770 So let me delete it. 39 00:02:29,430 --> 00:02:34,800 And then the way objects per operator works is we are still going to return a new object. 40 00:02:35,040 --> 00:02:36,930 So that still stays the same. 41 00:02:37,290 --> 00:02:39,030 But then if we type. 42 00:02:39,060 --> 00:02:47,250 Dot, dot, dot and then state what effectively we're doing, we're copying pasting all the values from 43 00:02:47,250 --> 00:02:47,970 my old state. 44 00:02:48,390 --> 00:02:49,800 No, I'm not mutating. 45 00:02:50,100 --> 00:02:52,440 I'm just copying, pasting the values. 46 00:02:52,650 --> 00:02:56,310 So now I have access to all the old state values. 47 00:02:56,730 --> 00:03:03,980 Now the thing is, if I type here which property I want to change, for example, I know I have the 48 00:03:03,980 --> 00:03:04,770 account correct. 49 00:03:04,980 --> 00:03:10,530 And if I would want to affect the account, I just need to type count property and now I'm going to 50 00:03:10,530 --> 00:03:13,170 override that and set it to a new value. 51 00:03:13,410 --> 00:03:15,010 So what is going to be my new value? 52 00:03:15,330 --> 00:03:23,370 Well, I'm going to set my account to be equal to state dot count minus one, so that still stays exactly 53 00:03:23,370 --> 00:03:23,910 the same. 54 00:03:24,300 --> 00:03:30,270 The difference here in this case, since I have multiple properties now, instead of just creating a 55 00:03:30,270 --> 00:03:37,770 new property and then using the old value, now I'm actually copying pasting the properties from the 56 00:03:37,770 --> 00:03:38,670 old state as well. 57 00:03:38,910 --> 00:03:42,450 And what I'm talking about, the other properties, the ones that I'm not changing. 58 00:03:42,780 --> 00:03:46,650 So now in this case, let me change this around for all of them. 59 00:03:47,280 --> 00:03:55,050 So like I said, I just need to add here that the objects per operator, so DataDot and then old state, 60 00:03:55,170 --> 00:04:02,340 so just spread out all the state properties that are coming from the old state and then return the count 61 00:04:02,340 --> 00:04:03,510 one change. 62 00:04:03,810 --> 00:04:08,970 And then of course I would want to do the same one for a reset as well, because I'm still looking for 63 00:04:08,970 --> 00:04:09,510 Ajan. 64 00:04:09,810 --> 00:04:17,040 So let me go down to that then state comma and now I'm overriding the account, let me say it. 65 00:04:17,190 --> 00:04:20,360 And now at the very bottom I still have my job. 66 00:04:20,550 --> 00:04:29,370 So this would be the syntax if our initial store or initial state has more values and just to this home 67 00:04:29,700 --> 00:04:33,150 we're going to create one for the name just so we can see what happens. 68 00:04:33,330 --> 00:04:41,220 If we're changing the value for money now instead of round, I'm going to go with change and name change 69 00:04:42,070 --> 00:04:42,810 name. 70 00:04:43,030 --> 00:04:49,680 Now, again, I'm going to copy and paste Mexico and somewhere here I'm going to check for that action 71 00:04:49,680 --> 00:04:50,000 type. 72 00:04:50,370 --> 00:04:58,920 So maybe right after that I'm going to say if action that type is equal to change name, well, then 73 00:04:58,920 --> 00:04:59,820 I would want to change it to. 74 00:05:00,490 --> 00:05:01,690 How do we do that again? 75 00:05:01,710 --> 00:05:08,080 We return a new object, I'm going to spread out the properties from the old state, so essentially 76 00:05:08,080 --> 00:05:09,220 I'm going to copy and paste them. 77 00:05:09,520 --> 00:05:16,400 And then instead of changing the count, I'm going to change my name to Bob or maybe Bubble. 78 00:05:16,630 --> 00:05:17,570 That's also fine. 79 00:05:17,830 --> 00:05:24,460 So now in the bottom, the count is two and the name is Bulbul or whatever. 80 00:05:24,460 --> 00:05:25,510 You place it over here. 81 00:05:25,990 --> 00:05:33,490 So, again, if we have multiple properties in our state, then we cannot just simply return a new object 82 00:05:33,640 --> 00:05:36,960 with just one property that we would want to change effectively. 83 00:05:37,180 --> 00:05:42,640 We need to make sure that we get all the properties and then only the ones that we would want overwrite 84 00:05:42,790 --> 00:05:44,030 or give it a new value. 85 00:05:44,320 --> 00:05:46,220 Those are the ones that we're adding here. 86 00:05:46,330 --> 00:05:49,510 Now, of course, we're not limited to just changing one property. 87 00:05:49,900 --> 00:05:56,380 For example, if I have decrease, I could also change my name here, since that is the second property. 88 00:05:56,710 --> 00:06:00,820 Keep in mind, if you're going to try to change some kind of property, that is not only the object, 89 00:06:01,210 --> 00:06:02,830 of course, that will not make sense. 90 00:06:03,010 --> 00:06:08,020 But since I know that I have two properties, I have the count and I have the name, for example, here 91 00:06:08,020 --> 00:06:12,430 I'm going to write honor now again, if I'm going to check the third. 92 00:06:12,830 --> 00:06:16,030 So, of course, that is after my first decrease. 93 00:06:16,510 --> 00:06:19,480 I'm going to see that name is right now. 94 00:06:19,990 --> 00:06:21,760 So the count is negative one. 95 00:06:22,240 --> 00:06:25,210 But then I set up my name to be.