1 00:00:01,020 --> 00:00:04,480 In the last section we put together our actions index not just file. 2 00:00:04,500 --> 00:00:06,590 It's all done now so I'm going to close that thing up. 3 00:00:06,870 --> 00:00:12,350 And then inside of my reducers directory I'm going to create a new file called as you might guess index. 4 00:00:12,430 --> 00:00:18,660 Yes like so so inside of here we're going to write out both of our reducers that we need and then we're 5 00:00:18,660 --> 00:00:22,770 going to eventually export them from this file so that they can be used somewhere else inside of our 6 00:00:22,770 --> 00:00:24,410 project. 7 00:00:24,420 --> 00:00:29,730 Now we're going to have our two reducers first saw one that is going to return a static list of songs 8 00:00:30,270 --> 00:00:35,730 and then the second one that is going to allow our user to select a very specific song once they click 9 00:00:35,730 --> 00:00:42,810 on the select button so we'll first put together our static list of songs reducer. 10 00:00:42,830 --> 00:00:51,870 So back inside of my code editor I'm going to say Konst songs reducer and then I'll assign this an arrow 11 00:00:51,870 --> 00:00:58,490 function like so so as I mentioned this is going to have a static list of songs it's a static array 12 00:00:58,820 --> 00:01:00,440 so there will be no arguments. 13 00:01:00,440 --> 00:01:04,640 We need to worry about here we don't need to look at any actions because we never expect to change it 14 00:01:04,640 --> 00:01:06,150 in any way shape or form. 15 00:01:06,350 --> 00:01:11,810 As I mentioned a little bit ago it's really overkill to put this list of songs into introducer but I 16 00:01:11,810 --> 00:01:17,570 just want to show you how we could really completely redux ify so to speak and application. 17 00:01:17,570 --> 00:01:23,690 So from this producer I'm going to return an array of objects where every object represents a different 18 00:01:23,690 --> 00:01:24,530 song. 19 00:01:25,350 --> 00:01:28,030 Well you will say that every song has a title property. 20 00:01:28,180 --> 00:01:33,410 So maybe I'll give this first song a title like I don't know what songs are there. 21 00:01:33,430 --> 00:01:34,160 Even these days. 22 00:01:34,180 --> 00:01:36,070 Let's let's look at really quick. 23 00:01:36,240 --> 00:01:37,630 About 90s songs. 24 00:01:39,750 --> 00:01:42,730 Ok got Backstreet Boys. 25 00:01:43,130 --> 00:01:44,500 Oh this is awful. 26 00:01:44,660 --> 00:01:45,410 Ok whatever. 27 00:01:45,410 --> 00:01:46,510 No Scrubs in Macarena. 28 00:01:46,520 --> 00:01:47,370 That's what we're doing. 29 00:01:47,370 --> 00:01:49,050 So no scrubs on. 30 00:01:49,100 --> 00:01:55,840 I'll give this thing a duration of four minutes five seconds and then I'll put on another song here 31 00:01:55,870 --> 00:02:02,690 I'll do the Macarena for the duration of I don't know two minutes and 30 seconds and we'll do two more 32 00:02:02,690 --> 00:02:04,230 really quickly. 33 00:02:04,460 --> 00:02:05,410 This is awful. 34 00:02:05,450 --> 00:02:05,690 OK. 35 00:02:05,690 --> 00:02:13,270 All star with a duration of three minutes 15 seconds. 36 00:02:14,710 --> 00:02:22,020 And then one more write Backstreet Boys I guess I want it that way. 37 00:02:22,020 --> 00:02:24,140 I don't really but whatever. 38 00:02:26,120 --> 00:02:30,280 And I'll give it a duration of one minute forty five seconds. 39 00:02:30,290 --> 00:02:30,560 All right. 40 00:02:30,560 --> 00:02:31,100 So that's it. 41 00:02:31,100 --> 00:02:34,010 That is our song data right there does it my guess. 42 00:02:34,100 --> 00:02:38,960 Totally fixed totally static totally randomized more or less with fixed durations. 43 00:02:39,050 --> 00:02:44,630 Now the only reason I made these durations strings was just to expect or express a duration easily with 44 00:02:44,630 --> 00:02:46,110 like our minutes Colin. 45 00:02:46,130 --> 00:02:49,490 And then the second. 46 00:02:49,520 --> 00:02:49,760 All right. 47 00:02:49,760 --> 00:02:51,100 So there's our songs producer. 48 00:02:51,120 --> 00:02:58,400 So now we're going to work on the more interesting reducer the reducer for selecting a specific song. 49 00:02:58,400 --> 00:03:01,560 So now we're going to have to really think about how to put this one together. 50 00:03:01,970 --> 00:03:05,170 All flip back over and underneath the existing reducer. 51 00:03:05,180 --> 00:03:11,350 I'll put my next one and I'll say Let's call this what do we have a selected song reducer. 52 00:03:16,170 --> 00:03:20,530 This is going to be called with a first argument of the currently selected song. 53 00:03:20,790 --> 00:03:27,540 And so I'm going to refer to that as selected song or defaulted to be no to indicate that when our application 54 00:03:27,570 --> 00:03:32,260 first starts up we are not going to have any selected song it's just nil. 55 00:03:32,370 --> 00:03:38,670 And then as a second argument will be our action object so we're going to look at that action object. 56 00:03:38,680 --> 00:03:42,480 We're going to inspect its type if its type is song selected. 57 00:03:42,670 --> 00:03:43,790 Then we're going to return. 58 00:03:43,790 --> 00:03:50,200 It's Paillard property because remember our select song action over here has a payload of the song that 59 00:03:50,200 --> 00:03:53,410 the user is trying to select. 60 00:03:53,460 --> 00:04:02,570 So I'm going to say if action not type equals and remember that will be our one action type song underscore 61 00:04:02,600 --> 00:04:06,940 selected. 62 00:04:07,080 --> 00:04:09,760 And if that is the case then I'm going to return. 63 00:04:10,140 --> 00:04:12,570 Action Daut payload. 64 00:04:13,020 --> 00:04:20,150 And if that's not the case then I will return whatever are currently selected song is now one thing 65 00:04:20,150 --> 00:04:25,960 I want to mention here is that as we have written out this producer we only have one action creator 66 00:04:25,960 --> 00:04:30,670 inside of our application right now but we've still written out an if statement assuming that we might 67 00:04:30,670 --> 00:04:33,100 have other actions at some point in the future. 68 00:04:33,100 --> 00:04:38,350 So technically for our current app we don't really need this if statement because we're only ever going 69 00:04:38,350 --> 00:04:41,200 to see actions of type songs selected. 70 00:04:41,200 --> 00:04:46,450 However just to be kind of hygenic and make sure that if we ever expand our application in the future 71 00:04:46,450 --> 00:04:51,640 with additional actions and additional types we're not going to somehow ruin our code here and break 72 00:04:51,640 --> 00:04:54,360 our selected song we're douceur. 73 00:04:54,390 --> 00:04:54,720 All right. 74 00:04:54,720 --> 00:04:58,070 So that's it for these to reduce hours we have to put together. 75 00:04:58,440 --> 00:05:02,460 Now let's take a quick pause right here when we continue in the next section we're going to wire these 76 00:05:02,460 --> 00:05:07,530 things up together with that combine reducers call that we had seen previously and then we'll start 77 00:05:07,530 --> 00:05:10,740 to wire up the provider inside of our application. 78 00:05:10,770 --> 00:05:12,590 So quick break and I'll see you in just a minute.