1 00:00:00,780 --> 00:00:02,390 In this video we're going to move on to it. 2 00:00:02,390 --> 00:00:04,250 Rule number three around reducers. 3 00:00:04,430 --> 00:00:08,030 So this one is not the worst thing in the world with the reducer. 4 00:00:08,030 --> 00:00:10,780 We must not reach out of itself. 5 00:00:10,790 --> 00:00:15,710 Now that term isn't super clear also a diagram just a second but essentially reduced or must not reach 6 00:00:15,800 --> 00:00:21,050 out of itself or out of its own function to decide what value to return. 7 00:00:21,140 --> 00:00:26,570 And so with this rule right here the declaration or the summation of it what we usually say about reducers 8 00:00:26,600 --> 00:00:29,030 are that they are supposed to be pure. 9 00:00:29,040 --> 00:00:32,390 So let me tell you a little bit more about what this rule is really talking about. 10 00:00:32,390 --> 00:00:37,790 All right so the idea here is that anytime that we call a producer with an action and our previous state 11 00:00:37,790 --> 00:00:43,490 value we're not supposed to reach out of this function whatsoever we are not supposed to go off and 12 00:00:43,490 --> 00:00:51,230 make an API request or to try to read some file off our hard drive or to solicit the user for some input 13 00:00:51,290 --> 00:00:57,950 or to reach into the DOM and try to pull some value out of a div or a label or input or something like 14 00:00:57,950 --> 00:00:58,860 that. 15 00:00:59,060 --> 00:01:05,150 When a producer gets called it is only supposed to look at the previous state value and the action object 16 00:01:05,210 --> 00:01:07,180 to decide what to return. 17 00:01:07,190 --> 00:01:14,130 So inside of all reducers that we write like our posts reduce right here we are never going to write 18 00:01:14,190 --> 00:01:14,790 any code. 19 00:01:14,790 --> 00:01:23,520 I mean the label is as bad that says like return document dot document dot query selector of some like 20 00:01:23,580 --> 00:01:25,550 input element or something like that. 21 00:01:25,650 --> 00:01:33,420 We're never going to try to return the result of making some network requests like ex-CEO get my list 22 00:01:33,420 --> 00:01:35,250 a post or something like that. 23 00:01:35,280 --> 00:01:41,120 The only thing that we're ever going to return is going to be some computation done on the two arguments. 24 00:01:41,160 --> 00:01:48,090 So like that state argument the first argument and the action that this thing gets called with so good 25 00:01:48,240 --> 00:01:54,360 we would return some type of combination or variation based upon the state plus action objects. 26 00:01:54,360 --> 00:01:55,810 Now this is not real code right here. 27 00:01:55,830 --> 00:02:00,160 This is just to give you an idea we want to take that state argument and the action argument. 28 00:02:00,270 --> 00:02:02,240 We want to do some computation on them. 29 00:02:02,250 --> 00:02:06,340 You know maybe a for loop maybe filtering maybe whatever it needs to be. 30 00:02:06,480 --> 00:02:08,480 And that's going to be the value that we return. 31 00:02:08,520 --> 00:02:14,450 We're never going to reach out of this producer Now again this entire idea right here is what we refer 32 00:02:14,450 --> 00:02:16,680 to as keeping a producer here. 33 00:02:16,730 --> 00:02:22,500 So with a pure function or a pure reducer we are only ever going to return values that use there it's 34 00:02:22,640 --> 00:02:24,240 input arguments. 35 00:02:24,550 --> 00:02:25,790 Okay so that's it. 36 00:02:25,990 --> 00:02:27,620 Let's take another quick pause. 37 00:02:27,740 --> 00:02:30,260 The next rule is where things start to get really interesting. 38 00:02:30,260 --> 00:02:30,590 All right. 39 00:02:30,590 --> 00:02:34,510 So just hold on for a second and we'll tackle this last rule in the next video.