1 00:00:00,240 --> 00:00:00,760 Beautiful. 2 00:00:00,960 --> 00:00:07,950 Once we have set up our store and reducer, now we can zero in on the specifics of the producer. 3 00:00:08,280 --> 00:00:14,040 And when it comes to producer, again, like I previously already mentioned, producer function is used 4 00:00:14,040 --> 00:00:18,930 to update our store and it takes two arguments state and action. 5 00:00:19,260 --> 00:00:26,910 And you can think of state as an old state or state before the update and action of what happened in 6 00:00:26,910 --> 00:00:31,540 your application or what kind of update you would want to make to your store. 7 00:00:31,800 --> 00:00:36,600 Now, easy way of thinking of actions is thinking what is the user doing? 8 00:00:36,780 --> 00:00:38,420 So, for example, we have the card. 9 00:00:38,790 --> 00:00:41,850 So what if a user would like to click on the increase? 10 00:00:41,850 --> 00:00:48,180 But well, we would set up the functionality where if that happens, then of course we increase the 11 00:00:48,180 --> 00:00:49,380 amount of items. 12 00:00:49,380 --> 00:00:50,130 We have an ID card. 13 00:00:50,340 --> 00:00:52,970 We also set up to total and all that. 14 00:00:53,100 --> 00:00:58,150 So the same would work if we decrease, if we remove and along those lines. 15 00:00:58,470 --> 00:01:03,990 Now, of course, since there are arguments, you can technically name them however you like, but a 16 00:01:03,990 --> 00:01:07,850 common practice is naming them state and action. 17 00:01:08,190 --> 00:01:14,400 Now, once we pass in our parameters, then I would like to console them just so we can see what is 18 00:01:14,400 --> 00:01:14,820 happening. 19 00:01:15,120 --> 00:01:19,410 So I'm going to go with the object in this case because I think it's going to be more representative 20 00:01:19,650 --> 00:01:22,740 and I'm going to go state and action. 21 00:01:22,960 --> 00:01:26,940 So once we cancel, like both of them, we notice something really interesting. 22 00:01:27,210 --> 00:01:32,670 So as far as state at the moment, it is undefined and then I'm not going to cover the action right 23 00:01:32,670 --> 00:01:32,940 now. 24 00:01:32,960 --> 00:01:38,910 This would be just the default action that is passed into initialized everything from the redox. 25 00:01:39,030 --> 00:01:41,580 So later we were going to create our own actions. 26 00:01:41,880 --> 00:01:48,080 But at this point in time, redacts just passes a default action which initializes everything. 27 00:01:48,390 --> 00:01:50,640 So we our state, we have our action. 28 00:01:50,880 --> 00:01:55,490 But of course, now we need to deal with the fact that our state at the moment is undefined. 29 00:01:55,950 --> 00:01:57,270 So what's up with that? 30 00:01:57,630 --> 00:02:02,850 When you say why don't we have to create store, we can pass in the second argument, and that would 31 00:02:02,850 --> 00:02:06,710 be our initial store, of course, we would still need to set it up. 32 00:02:07,380 --> 00:02:15,540 So, for example, above the register, I can say initial store and I'm going to create it as a variable, 33 00:02:15,540 --> 00:02:20,160 of course, const initial store, initial store. 34 00:02:20,160 --> 00:02:23,550 And for the time being there will be equal to an object. 35 00:02:23,700 --> 00:02:28,950 And then within the object I'm going to have the current property and the count will be equal to zero. 36 00:02:29,190 --> 00:02:34,850 Now, like I said, the second argument and a great store is where we pass in our initial store. 37 00:02:35,160 --> 00:02:41,460 So I'm going to go with initial store and now in a console, we should still see our default action. 38 00:02:41,760 --> 00:02:47,210 That would be that funny action with the type and then state now is count. 39 00:02:47,610 --> 00:02:52,890 So in the beginning it was undefined because we didn't pass any kind of initial value. 40 00:02:53,130 --> 00:02:59,340 But then, of course, once we set up our initial store, now this is our initial state of the application. 41 00:02:59,850 --> 00:03:03,210 And then when it comes to our producer, we have one of the two options. 42 00:03:03,720 --> 00:03:06,630 Either we are going to return updated state. 43 00:03:07,020 --> 00:03:13,410 So state after the action happened, for example, again, user decided to remove the item. 44 00:03:13,800 --> 00:03:18,480 So we're going to have functionality that checks for that action that actually happened. 45 00:03:18,750 --> 00:03:24,390 Then, of course, we're going to do our calculations, remove that product from the state, and then 46 00:03:24,390 --> 00:03:26,790 return a new state without that product. 47 00:03:27,210 --> 00:03:29,430 But always, always has a default. 48 00:03:29,670 --> 00:03:34,120 You should return the old state so state before the update. 49 00:03:34,530 --> 00:03:40,710 So if, for example, some kind of action happen and you are not checking for that action, you should 50 00:03:40,710 --> 00:03:43,890 always, always return to state before the update. 51 00:03:44,070 --> 00:03:50,190 That's why in the bottom, I'm going to write return state, essentially what I'm doing, as I'm saying. 52 00:03:50,190 --> 00:03:50,460 All right. 53 00:03:50,460 --> 00:03:51,930 I'm going to be checking for the actions. 54 00:03:52,320 --> 00:03:58,470 If none of the actions match to whatever action just happened in my application, then I'm just going 55 00:03:58,470 --> 00:04:02,100 to return the state the way it was before the update.