1 00:00:00,150 --> 00:00:06,690 Early on in the project, I showed you how we can set up a initial store by passing it as a second argument 2 00:00:06,900 --> 00:00:08,420 in our create store. 3 00:00:09,300 --> 00:00:17,520 In Redox, their alternative way, how we can pass in the store or initial state into our producer. 4 00:00:17,970 --> 00:00:19,590 And the concept is following. 5 00:00:19,590 --> 00:00:21,960 Where has your application grows bigger? 6 00:00:22,290 --> 00:00:25,410 You would want to start combining your producers. 7 00:00:25,710 --> 00:00:30,680 So essentially you don't want to set up all the functionality in one reducer. 8 00:00:30,990 --> 00:00:34,110 So that's why you'll start setting up separate producers. 9 00:00:34,320 --> 00:00:40,080 And in that case you would want to pass in the state directly in the register. 10 00:00:40,500 --> 00:00:46,650 But at the moment we already know that if I remove my initial store, of course I will have an error 11 00:00:47,010 --> 00:00:54,270 because my producer will get on the phone, because at the moment, notice I have my state, I'm relying 12 00:00:54,270 --> 00:01:00,650 on my old state, but since initially state is undefined, then all the functionality goes bananas. 13 00:01:01,020 --> 00:01:07,230 Now I can tell right away that we will not implement the whole setup for combined reducers where we 14 00:01:07,230 --> 00:01:12,900 set up separate producers and then combine them together because I think our application is not big 15 00:01:12,900 --> 00:01:13,140 enough. 16 00:01:13,320 --> 00:01:15,120 So it doesn't really make sense. 17 00:01:15,510 --> 00:01:18,770 But since I would want you would be aware of the other setup as well. 18 00:01:19,140 --> 00:01:24,150 I'll show you how I can pass initial store directly in the register. 19 00:01:24,570 --> 00:01:26,550 So we removed it from create store. 20 00:01:26,850 --> 00:01:27,660 We got an error. 21 00:01:27,990 --> 00:01:29,610 OK, we already expected that. 22 00:01:29,910 --> 00:01:31,020 Now, how does it work? 23 00:01:31,410 --> 00:01:35,370 Well, reducer is a function, correct in function. 24 00:01:35,550 --> 00:01:42,630 We have something called default parameters that came along with ESX and the way we write default parameters 25 00:01:42,750 --> 00:01:50,580 is in a following fashion where if I have my parameter and for example, if my parameter is undefined, 26 00:01:50,850 --> 00:01:53,520 I'll set it to some kind of default value. 27 00:01:53,850 --> 00:02:00,930 And you already saw that in the card container where I had the card prop that was coming, of course, 28 00:02:01,170 --> 00:02:05,590 from my maps that props, but I also set it equal to an empty array. 29 00:02:05,940 --> 00:02:13,650 So, for example, if for some reason my card is not an array, then at least I'll have the empty array 30 00:02:13,650 --> 00:02:14,760 as a default value. 31 00:02:15,270 --> 00:02:21,030 Because if we have the statement that is depending on that, since I'm checking for the card length, 32 00:02:21,030 --> 00:02:26,550 then I'm saying if it is equal to zero, then display this and then if it's not, then display something. 33 00:02:26,760 --> 00:02:28,350 At least I will have something. 34 00:02:28,650 --> 00:02:33,300 So it's not going to be an error and we'll do exactly the same introducer. 35 00:02:33,630 --> 00:02:37,590 So I have my state and I know that initially it will be undefined. 36 00:02:37,890 --> 00:02:43,100 But of course in this case I could set it equal to whatever I have in my initial store. 37 00:02:43,410 --> 00:02:47,340 Now, one thing that I would need to do is, of course, cut it out from the app. 38 00:02:47,340 --> 00:02:54,750 Just let me grab it, then copy and paste in the reducer like so now I'll change these values around. 39 00:02:54,750 --> 00:03:01,860 Of course, I don't need them anymore, so I will go with zero and zero and also remember that we have 40 00:03:01,860 --> 00:03:06,270 the car items so we would need to import our car items. 41 00:03:06,630 --> 00:03:10,980 So for the time being, let me say it, of course we'll still have an error because I haven't assigned 42 00:03:10,980 --> 00:03:12,030 my state something. 43 00:03:12,540 --> 00:03:18,000 But let me head back to objets and of course I can just copy and paste or cut it out. 44 00:03:18,000 --> 00:03:18,660 I don't need it. 45 00:03:19,140 --> 00:03:25,230 So let me cut it out and then in the reducer, I don't know, right after the actions, I guess I will 46 00:03:25,230 --> 00:03:31,950 import my car items and now I'll set my store if it is undefined, which it will be undefined in the 47 00:03:31,950 --> 00:03:35,940 beginning, equal to my initial store. 48 00:03:36,180 --> 00:03:37,650 And now you'll see that moment. 49 00:03:37,650 --> 00:03:42,330 We said everything again works and again, it comes in very handy. 50 00:03:42,600 --> 00:03:50,030 Once you start combining reducers, once you start splitting up the code from one producer into multiple 51 00:03:50,220 --> 00:03:56,390 juicers and you're able to pass in the actual state directly in the producer. 52 00:03:56,640 --> 00:04:02,700 So, for example, you could have some kind of modal reducer where it will have only one property. 53 00:04:02,910 --> 00:04:03,960 Is the model open? 54 00:04:04,140 --> 00:04:09,780 And then you'll toggle that because there's really no point for you to keep on adding everything within 55 00:04:09,780 --> 00:04:15,810 that one state object and then keep on setting up the functionality because eventually it will get hard 56 00:04:15,810 --> 00:04:16,820 to manage again. 57 00:04:16,830 --> 00:04:18,960 We will not cover this in this project. 58 00:04:18,960 --> 00:04:25,800 But I wanted you to be aware of the fact that not only we can pass in our initial store when we set 59 00:04:25,800 --> 00:04:34,430 up our create store, but also we can do that directly in reducer if we use S6 default parameters or 60 00:04:34,440 --> 00:04:40,380 if the parameter is undefined, then I just said equal to my initial store and all my functionality 61 00:04:40,380 --> 00:04:41,370 will still or.