1 00:00:01,020 --> 00:00:06,330 In the last section we created our redux store inside the index such as file and wired up the store 2 00:00:06,330 --> 00:00:07,830 to our component hierarchy. 3 00:00:07,830 --> 00:00:12,460 Thanks to the provider had provided to us by the reactor redux library. 4 00:00:12,480 --> 00:00:16,980 We're now going to progress on to creating all the different reducers or at least one reducer for right 5 00:00:16,980 --> 00:00:20,440 now that's going to use inside of our redux store. 6 00:00:20,530 --> 00:00:27,210 We'll create the reducer we'll then import it into this index file and replace this little dummy reducer 7 00:00:27,210 --> 00:00:31,290 right here with the real one that we want to use inside of our application. 8 00:00:31,290 --> 00:00:37,790 Now it's a reminder we're going to have two distinct reducers at least inside of our application. 9 00:00:37,800 --> 00:00:42,420 The first is the author douceur that is going to be responsible for deciding whether or not the user 10 00:00:42,420 --> 00:00:43,830 is currently logged in. 11 00:00:43,900 --> 00:00:49,080 And the second will be a survey's reducer which is responsible for recording a list of all the different 12 00:00:49,080 --> 00:00:51,540 surveys that a user has created. 13 00:00:51,540 --> 00:00:55,290 Now over time we might add in a couple of other reducers if required. 14 00:00:55,350 --> 00:00:59,900 But right now I feel pretty confident that this will at least get us started. 15 00:01:00,000 --> 00:01:02,340 We're not going to create the survey's reducer just yet. 16 00:01:02,340 --> 00:01:07,590 We'll come back to that later after we've kind of implemented surveys a little bit on the back end server. 17 00:01:07,620 --> 00:01:12,030 So right now I want to create a file to Howze our reducer. 18 00:01:12,150 --> 00:01:17,820 I want to pass it to our combined reducers call and then pass that off to our redux store. 19 00:01:18,390 --> 00:01:20,600 So I'm going to change back over to my code Ed.. 20 00:01:20,820 --> 00:01:25,990 We're going to create a new folder to house all the different producers inside of our application. 21 00:01:26,070 --> 00:01:34,110 So inside of the SIRC directory I'll make a new folder called reducers and do triple check your spelling 22 00:01:34,110 --> 00:01:35,210 on reducers. 23 00:01:35,310 --> 00:01:36,270 Very common typo. 24 00:01:36,300 --> 00:01:42,800 I do is to flip the r in that e and they're really easy typo type automake inside the reducers directory. 25 00:01:42,810 --> 00:01:48,370 We're going to immediately create two different files one is going to be intended to house the author 26 00:01:48,370 --> 00:01:49,010 douceur. 27 00:01:49,110 --> 00:01:52,420 So I'm going to make Auth. reduce Yes. 28 00:01:52,620 --> 00:01:57,630 And do note that I'm using a lowercase a here to indicate that we are going to export a function from 29 00:01:57,630 --> 00:02:02,410 this file as opposed to a component class or something like that. 30 00:02:02,460 --> 00:02:07,420 Then the second file and going to make is going to be called an index file. 31 00:02:07,510 --> 00:02:09,430 So index dot J Yes. 32 00:02:10,020 --> 00:02:16,230 Now immediately Yes we do now have to index dot J.S. files inside of our project. 33 00:02:16,230 --> 00:02:17,450 I know this is a pain. 34 00:02:17,490 --> 00:02:19,820 I know it's something that is tough to get used to. 35 00:02:20,070 --> 00:02:27,240 The purpose of calling these files indexed us is to allow us to simply import the reducers directory 36 00:02:27,660 --> 00:02:33,690 which by convention with import statements will automatically give us any file inside that directory 37 00:02:33,690 --> 00:02:34,880 that is called indexed on. 38 00:02:34,950 --> 00:02:36,040 Yes. 39 00:02:36,150 --> 00:02:41,310 So if you don't like the fact that we know how to index dodgiest files Trust me I'm with you. 40 00:02:41,340 --> 00:02:46,850 I don't really care for it myself but it is definitely convention inside of react and redux projects. 41 00:02:46,920 --> 00:02:49,140 So we're sticking with convention here. 42 00:02:49,770 --> 00:02:50,190 Okay. 43 00:02:50,310 --> 00:02:53,010 Well first start off inside the author Duzer file. 44 00:02:53,250 --> 00:02:55,260 So I'm now inside of author reducer. 45 00:02:55,300 --> 00:03:01,000 J.S. inside of here we're going to create a reducer and immediately export it. 46 00:03:01,080 --> 00:03:06,630 Now as a reminder kind of assuming here that we're all at least passingly familiar with reducers we 47 00:03:06,630 --> 00:03:10,700 kind of have a sense of what they do if you're not familiar with all this stuff. 48 00:03:10,710 --> 00:03:15,960 You know if I'm moving too fast at this point remember you can always look up some of different resources 49 00:03:15,980 --> 00:03:21,080 of attached to the end of the course and get a little refresher on redox and how it works. 50 00:03:21,090 --> 00:03:21,880 OK. 51 00:03:22,560 --> 00:03:28,710 So inside the author Duzer file and place our expert default statements are going to export a function 52 00:03:29,760 --> 00:03:35,370 the function we called with two arguments the first will be our state object that is responsible for 53 00:03:35,370 --> 00:03:41,010 this reducer and then the second object or a second argument I should say would be our action object 54 00:03:42,150 --> 00:03:43,400 inside of the reducer. 55 00:03:43,410 --> 00:03:46,540 We'll switch over the actions type. 56 00:03:46,620 --> 00:03:50,440 Right now we don't have any types defined inside of our application. 57 00:03:50,550 --> 00:03:57,720 So I'm going to assume that we're just going to have a single case the default case default from which 58 00:03:57,720 --> 00:03:59,810 we will just return our state. 59 00:03:59,820 --> 00:04:03,140 So we're going to assume hey no change to state is necessary. 60 00:04:03,300 --> 00:04:07,310 Just return our state object like so. 61 00:04:07,430 --> 00:04:09,680 OK so then the last thing we do inside of here. 62 00:04:09,720 --> 00:04:13,530 Remember that our state object initially starts off as undefined. 63 00:04:13,530 --> 00:04:16,870 So we have to provide some initial value for it. 64 00:04:16,890 --> 00:04:23,910 So in this case I'm just going to assume that our initial state is going to be an empty object now incredibly 65 00:04:23,910 --> 00:04:27,130 likely that we'll come back and change this at some point in the future. 66 00:04:27,210 --> 00:04:30,830 But right now I think it's a good starting place. 67 00:04:30,870 --> 00:04:31,270 OK. 68 00:04:31,380 --> 00:04:32,790 So here's our Auth. reducer. 69 00:04:32,790 --> 00:04:33,960 This is looking pretty good. 70 00:04:34,140 --> 00:04:35,310 Let's take a quick break. 71 00:04:35,310 --> 00:04:40,860 When we return we're going to import this into our reducers index file. 72 00:04:41,040 --> 00:04:46,830 We'll then wired up with a combined reducers call and then hook that up to the redux store inside of 73 00:04:46,830 --> 00:04:49,060 our route index DHHS file. 74 00:04:49,140 --> 00:04:51,070 So I'll see you in just a second.